Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##Inglise tõlkeks vajalikud
- def typeToEN(letter):
- if letter == "V":
- return "R"
- elif letter == "O":
- return "B"
- elif letter == "E":
- return "P"
- elif letter == "K":
- return "K"
- elif letter == "L":
- return "Q"
- elif letter == "R":
- return "N"
- return " "
- def typeToEE(letter):
- if letter == "R":
- return "V"
- elif letter == "B":
- return "O"
- elif letter == "P":
- return "E"
- elif letter == "K":
- return "K"
- elif letter == "Q":
- return "L"
- elif letter == "N":
- return "R"
- return letter
- def ownerToEN(letter):
- if letter == "V":
- return "W"
- elif letter == "M":
- return "B"
- return " "
- def ownerToEE(letter):
- if letter == "W":
- return "V"
- elif letter == "B":
- return "M"
- return letter
- import time
- import random
- import operator
- import textwrap
- DIGITS1TO8 = "1 2 3 4 5 6 7 8".split()
- LETTERSATOH = "A B C D E F G H".split()
- def getNewBoardType():
- boardType = [[" "] * 8 for i in range(8)]
- for x in range(8):
- boardType[x][1] = "E"
- boardType[x][6] = "E"
- typeOrder = ["V", "R", "O", "L", "K", "O", "R", "V"]
- for x in range(8):
- boardType[x][0] = typeOrder[x]
- boardType[x][7] = typeOrder[x]
- return boardType
- def getNewBoardOwner():
- boardOwner = [[" "] * 8 for i in range(8)]
- for x in range(8):
- boardOwner[x][1] = "V"
- boardOwner[x][0] = "V"
- boardOwner[x][6] = "M"
- boardOwner[x][7] = "M"
- return boardOwner
- def getPrintMode():
- while True:
- printMode = input("Input the size of the board ([S] for large, [K] for medium, [V] for small): ")
- if len(printMode)==0:
- nope = ".avi"
- elif printMode[0].upper()=="S":
- printMode = "S"
- break
- elif printMode[0].upper()=="V":
- printMode = "V"
- break
- elif printMode[0].upper()=="K":
- printMode = "K"
- break
- return printMode
- def printBoard(printMode): #Lisasin veidi "print("")" et tekitada whitespace'i
- for y in range(8):
- for x in range(8):
- boardType[x][y] = typeToEN(boardType[x][y])
- boardOwner[x][y] = ownerToEN(boardOwner[x][y])
- if printMode == "S":
- print("")
- print(" ", end="")
- for x in range(8):
- print(" %s " %(LETTERSATOH[x]), end="")
- print("")
- for y in range(8):
- print(" "+"+--------"*8, end="")
- print("+")
- print(" "+"| "*8+"|")
- print(DIGITS1TO8[7-y], end = " ")
- for x in range(8):
- print("| %s%s " %(boardType[x][7-y], boardOwner[x][7-y]), end = "")
- print("| ", end = " ")
- print(DIGITS1TO8[7-y])
- print(" ", end="")
- for x in range(8):
- print("|%s%s " % (LETTERSATOH[x],DIGITS1TO8[8-y-1]), end = "")
- print("|")
- print(" "+"+--------"*8, end="")
- print("+")
- print(" ", end="")
- for x in range(8):
- print(" %s " %(LETTERSATOH[x]), end="")
- print("")
- print("")
- elif printMode == "V":
- print("")
- print(" ", end="")
- for x in range(8):
- print(" %s " %(LETTERSATOH[x]), end="")
- print("")
- for y in range(8):
- print(" "+"+---"*8, end="")
- print("+")
- print(DIGITS1TO8[7-y], end = " ")
- for x in range(8):
- print("|%s%s " %(boardType[x][7-y], boardOwner[x][7-y]), end = "")
- print("|", end = " ")
- print(DIGITS1TO8[7-y])
- print(" "+"+---"*8, end="")
- print("+")
- print(" ", end="")
- for x in range(8):
- print(" %s " %(LETTERSATOH[x]), end="")
- print("")
- print("")
- elif printMode == "K":
- print("")
- print(" ", end="")
- for x in range(8):
- print(" %s " %(LETTERSATOH[x]), end="")
- print("")
- for y in range(8):
- print(" "+"+----"*8, end="")
- print("+")
- print(DIGITS1TO8[7-y], end = " ")
- for x in range(8):
- print("| %s%s " %(boardType[x][7-y], boardOwner[x][7-y]), end = "")
- print("|", end = " ")
- print(DIGITS1TO8[7-y])
- print(" "+"+----"*8, end="")
- print("+")
- print(" ", end="")
- for x in range(8):
- print(" %s " %(LETTERSATOH[x]), end="")
- print("")
- print("")
- for y in range(8):
- for x in range(8):
- boardType[x][y] = typeToEE(boardType[x][y])
- boardOwner[x][y] = ownerToEE(boardOwner[x][y])
- def turnChange(turn):
- if turn == "V":
- turn = "M"
- else:
- turn = "V"
- return turn
- def posConvert(position):
- position = ((ord(position[0])-ord("A")), int(position[1])-1)
- return position
- def getMove(turn):
- while True:
- surrender = 0
- movesTogether = input("Insert your turn: ")
- if movesTogether.lower() == "surrender": #Alla andmine
- surrender = 1
- startPos = (0,0)
- endPos = (0,0)
- return startPos, endPos, surrender
- if len(movesTogether) == 4 and movesTogether[0].upper() in LETTERSATOH and movesTogether[2].upper() in LETTERSATOH and movesTogether[1] in DIGITS1TO8 and movesTogether[3] in DIGITS1TO8:
- startPos = str(movesTogether[0].upper()) + movesTogether[1]
- endPos = str(movesTogether[2].upper()) + movesTogether[3]
- startPos = posConvert(startPos)
- endPos = posConvert(endPos)
- if boardOwner[startPos[0]][startPos[1]] != turn:
- print("You don't have a piece there.")
- else:
- return startPos, endPos, surrender
- else:
- print("Input your move in the format [Start location letter][Start location number][Destination letter][Destination number]. For example, A2A3.")
- def checkCheck(X,boardType,boardOwner):
- Y = X[0] + 1
- while Y < 8:
- if boardOwner[Y][X[1]] == turn:
- break
- elif boardOwner[Y][X[1]] != " ":
- if boardType[Y][X[1]] == "V" or boardType[Y][X[1]] == "L": #paremal
- return True
- else:
- break
- Y += 1
- Y = X[0] - 1
- while Y > -1:
- if boardOwner[Y][X[1]] == turn:
- break
- elif boardOwner[Y][X[1]] != " ":
- if boardType[Y][X[1]] == "V" or boardType[Y][X[1]] == "L": #vasakul
- return True
- else:
- break
- Y -= 1
- Y = X[1] + 1
- while Y < 8:
- if boardOwner[X[0]][Y] == turn:
- break
- elif boardOwner[X[0]][Y] != " ":
- if boardType[X[0]][Y] == "V" or boardType[X[0]][Y] == "L": #üles
- return True
- else:
- break
- Y += 1
- Y = X[1] - 1
- while Y > -1:
- if boardOwner[X[0]][Y] == turn:
- break
- elif boardOwner[X[0]][Y] != " ":
- if boardType[X[0]][Y] == "V" or boardType[X[0]][Y] == "L": # alla
- return True
- else:
- break
- Y -= 1
- Y = X[0] + 1
- Z = X[1] + 1
- while Y < 8 and Z < 8:
- if boardOwner[Y][Z] == turn:
- break
- elif boardOwner[Y][Z] != " ":
- if boardType[Y][Z] == "O" or boardType[Y][Z] == "L": #Asimuut 45
- return True
- else:
- break
- Y += 1
- Z += 1
- Y = X[0] - 1
- Z = X[1] - 1
- while Y > -1 and Z > -1:
- if boardOwner[Y][Z] == turn:
- break
- elif boardOwner[Y][Z] != " ":
- if boardType[Y][Z] == "O" or boardType[Y][Z] == "L": #asimuut 225
- return True
- else:
- break
- Y -= 1
- Z -= 1
- Y = X[0] + 1
- Z = X[1] - 1
- while Y < 8 and Z > -1:
- if boardOwner[Y][Z] == turn:
- break
- elif boardOwner[Y][Z] != " ":
- if boardType[Y][Z] == "O" or boardType[Y][Z] == "L": #asimuut 135
- return True
- else:
- break
- Y += 1
- Z -= 1
- Y = X[0] - 1
- Z = X[1] + 1
- while Z < 8 and Y > -1:
- if boardOwner[Y][Z] == turn:
- break
- elif boardOwner[Y][Z] != " ":
- if boardType[Y][Z] == "O" or boardType[Y][Z] == "L": #asimuut 315
- return True
- else:
- break
- Y -= 1
- Z += 1
- #Ratsud
- if X[0]+2 < 8: #Paremal
- if X[1]+1 < 8:
- if boardType[X[0]+2][X[1]+1] == "R":
- if boardOwner[X[0]+2][X[1]+1] != turn:
- return True
- if X[1]-1 > -1:
- if boardType[X[0]+2][X[1]-1] == "R":
- if boardOwner[X[0]+2][X[1]-1] != turn:
- return True
- if X[0]-2 > -1: #Vasakul
- if X[1]+1 < 8:
- if boardType[X[0]-2][X[1]+1] == "R":
- if boardOwner[X[0]-2][X[1]+1] != turn:
- return True
- if X[1]-1 > -1:
- if boardType[X[0]-2][X[1]-1] == "R":
- if boardOwner[X[0]-2][X[1]-1] != turn:
- return True
- if X[1]+2 < 8: #Üleval
- if X[0]+1 < 8:
- if boardType[X[0]+1][X[1]+2] == "R":
- if boardOwner[X[0]+1][X[1]+2] != turn:
- return True
- if X[0]-1 > -1:
- if boardType[X[0]-1][X[1]+2] == "R":
- if boardOwner[X[0]-1][X[1]+2] != turn:
- return True
- if X[1]-2 > -1: #All
- if X[0]+1 < 8:
- if boardType[X[0]+1][X[1]-2] == "R":
- if boardOwner[X[0]+1][X[1]-2] != turn:
- return True
- if X[0]-1 > -1:
- if boardType[X[0]-1][X[1]-2] == "R":
- if boardOwner[X[0]-1][X[1]-2] != turn:
- return True
- if turn == "V":
- if X[1]+1 < 8:
- if X[0]+1 < 8:
- if boardType[X[0]+1][X[1]+1] == "E" and boardOwner[X[0]+1][X[1]+1] != turn:
- return True
- if X[0]-1 > -1:
- if boardType[X[0]-1][X[1]+1] == "E" and boardOwner[X[0]-1][X[1]+1] != turn:
- return True
- else:
- if X[1]-1 > -1:
- if X[0]+1 < 8:
- if boardType[X[0]+1][X[1]-1] == "E" and boardOwner[X[0]+1][X[1]-1] != turn:
- return True
- if X[0]-1 > -1:
- if boardType[X[0]-1][X[1]-1] == "E" and boardOwner[X[0]-1][X[1]-1] != turn:
- return True
- def checkValidity(turn, startPos, endPos):
- validMoves = []
- startx = startPos[0]
- starty = startPos[1]
- endx = endPos[0]
- endy = endPos[1]
- if boardType[startx][starty] == "E": #Lisab validMoves listi kõik võimalikud käigud etturi poolt.
- if turn == "V":
- if boardType[startx][starty+1] == " ":
- validMoves.append((startx,starty+1))
- if startx+1 < 8 and boardOwner[startx+1][starty+1] == "M":
- validMoves.append((startx+1,startPos[1]+1))
- if startx-1 > -1 and boardOwner[startx-1][starty+1] == "M":
- validMoves.append((startx-1,starty+1))
- if starty == 1 and boardType[startx][starty+2] == " ":
- validMoves.append((startx,3))
- if turn == "M":
- if boardType[startx][starty-1] == " ":
- validMoves.append((startx,starty-1))
- if startx+1 < 8 and boardOwner[startx+1][starty-1] == "V":
- validMoves.append((startx+1,starty-1))
- if startx-1 > -1 and boardOwner[startx-1][starty-1] == "V":
- validMoves.append((startx-1,starty-1))
- if starty == 6 and boardType[startx][starty-2] == " ":
- validMoves.append((startx,4))
- if boardType[startx][starty] == "K":
- if startx-1 > -1 and (boardOwner[startx-1][starty] != turn):
- validMoves.append((startx-1,starty))
- if startx+1 < 8 and (boardOwner[startx-1][starty] != turn):
- validMoves.append((startx+1,starty))
- if starty+1 < 8:
- for i in range(3):
- if startx-1+i < 8 and startx-1+i > - 1:
- if boardOwner[startx-1+i][starty+1] != turn:
- validMoves.append((startx-1+i,starty+1))
- if starty-1 > -1:
- for i in range(3):
- if startx-1+i < 8 and startx-1+i > - 1:
- if boardOwner[startx-1+i][starty-1] != turn:
- validMoves.append((startx-1+i,starty-1))
- if boardType[startx][starty] == "R":
- if starty+2 < 8:
- if startx-1 > -1:
- if boardOwner[startx-1][starty+2] != turn:
- validMoves.append((startx-1,starty+2))
- if startx+1 < 8:
- if boardOwner[startx+1][starty+2] != turn:
- validMoves.append((startx+1,starty+2))
- if starty-2 > -1:
- if startx-1 > -1:
- if boardOwner[startx-1][starty-2] != turn:
- validMoves.append((startx-1,starty-2))
- if startx+1 < 8:
- if boardOwner[startx+1][starty-2] != turn:
- validMoves.append((startx+1,starty-2))
- if startx+2 < 8:
- if starty-1 > -1:
- if boardOwner[startx+2][starty-1] != turn:
- validMoves.append((startx+2,starty-1))
- if starty+1 < 8:
- if boardOwner[startx+2][starty+1] != turn:
- validMoves.append((startx+2,starty+1))
- if startx-2 > -1 :
- if starty-1 > -1:
- if boardOwner[startx-2][starty-1] != turn:
- validMoves.append((startx-2,starty-1))
- if starty+1 < 8:
- if boardOwner[startx-2][starty+1] != turn:
- validMoves.append((startx-2,starty+1))
- if boardType[startx][starty] == "V" or boardType[startx][starty] == "L":
- for moveLength in range(1,8):
- if starty+moveLength < 8: #1. Üles
- nextTileNumber = (startx, (starty+moveLength))
- nextTileOwner = boardOwner[startx][starty+moveLength]
- if nextTileOwner != turn:
- if nextTileOwner == " ":
- validMoves.append(nextTileNumber)
- else:
- validMoves.append(nextTileNumber)
- break
- else:
- break
- for moveLength in range(1,8):
- if startx+moveLength < 8: #2. Paremale
- nextTileNumber = (startx+moveLength, starty)
- nextTileOwner = boardOwner[startx+moveLength][starty]
- if nextTileOwner != turn:
- if nextTileOwner == " ":
- validMoves.append(nextTileNumber)
- else:
- validMoves.append(nextTileNumber)
- break
- else:
- break
- for moveLength in range(1,8):
- if starty-moveLength > (-1): #3. Alla
- nextTileNumber = (startx, starty-moveLength)
- nextTileOwner = boardOwner[startx][starty-moveLength]
- if nextTileOwner != turn:
- if nextTileOwner == " ":
- validMoves.append(nextTileNumber)
- else:
- validMoves.append(nextTileNumber)
- break
- else:
- break
- for moveLength in range(1,8):
- if startx-moveLength > (-1): #4. Vasakule
- nextTileNumber = (startx-moveLength, starty)
- nextTileOwner = boardOwner[startx-moveLength][starty]
- if nextTileOwner != turn:
- if nextTileOwner == " ":
- validMoves.append(nextTileNumber)
- else:
- validMoves.append(nextTileNumber)
- break
- else:
- break
- if boardType[startx][starty] == "O" or boardType[startx][starty] == "L":
- for moveLength in range(1,8): #1. asimuut 45
- if startx+moveLength < 8 and starty+moveLength < 8:
- nextTileNumber = (startx+moveLength, starty+moveLength)
- nextTileOwner = boardOwner[startx+moveLength][starty+moveLength]
- if nextTileOwner != turn:
- if nextTileOwner == " ":
- validMoves.append(nextTileNumber)
- else:
- validMoves.append(nextTileNumber)
- break
- else:
- break
- for moveLength in range(1,8): #2. asimuut 135
- if startx+moveLength < 8 and starty-moveLength > (-1):
- nextTileNumber = (startx+moveLength, starty-moveLength)
- nextTileOwner = boardOwner[startx+moveLength][starty-moveLength]
- if nextTileOwner != turn:
- if nextTileOwner == " ":
- validMoves.append(nextTileNumber)
- else:
- validMoves.append(nextTileNumber)
- break
- else:
- break
- for moveLength in range(1,8): #1. asimuut 225
- if startx-moveLength > (-1) and starty-moveLength > (-1):
- nextTileNumber = (startx-moveLength, starty-moveLength)
- nextTileOwner = boardOwner[startx-moveLength][starty-moveLength]
- if nextTileOwner != turn:
- if nextTileOwner == " ":
- validMoves.append(nextTileNumber)
- else:
- validMoves.append(nextTileNumber)
- break
- else:
- break
- for moveLength in range(1,8): #1. asimuut 315
- if startx+moveLength > (-1) and starty+moveLength < 8:
- nextTileNumber = (startx-moveLength, starty+moveLength)
- nextTileOwner = boardOwner[startx-moveLength][starty+moveLength]
- if nextTileOwner != turn:
- if nextTileOwner == " ":
- validMoves.append(nextTileNumber)
- else:
- validMoves.append(nextTileNumber)
- break
- else:
- break
- if check == True:
- boardTypeTemp = [[" "] * 8 for i in range(8)]
- boardOwnerTemp = [[" "] * 8 for i in range(8)]
- for i in range(8):
- for y in range(8):
- boardTypeTemp[i][y]=(boardType[i][y])
- boardOwnerTemp[i][y]=(boardOwner[i][y])
- boardTypeTemp[endPos[0]][endPos[1]] = boardType[startPos[0]][startPos[1]]
- boardOwnerTemp[endPos[0]][endPos[1]] = turn
- boardTypeTemp[startPos[0]][startPos[1]] = " "
- boardOwnerTemp[startPos[0]][startPos[1]] = " "
- if boardType[startx][starty] == "K":
- if checkCheck((endPos[0],endPos[1]),boardTypeTemp,boardOwnerTemp):
- print("Check! You can't move there.")
- return False
- elif turn == "V":
- if checkCheck(whiteKingPos,boardTypeTemp,boardOwnerTemp):
- print("Check! You can't move there.")
- return False
- else:
- if checkCheck(blackKingPos,boardTypeTemp,boardOwnerTemp):
- print("Check! You can't move there.")
- return False
- if boardType[startx][starty] == "K": ################ Vangerdus
- if turn == "V":
- if (endx, endy) == (6, 0) and "V" not in kingSideCastle:
- if boardType[5][0] == " " and not checkCheck((5,0),boardType,boardOwner) and boardType[6][0] == " " and not checkCheck((6,0),boardType,boardOwner):
- return "whiteKingSide"
- elif (endx, endy) == (2, 0) and "V" not in queenSideCastle:
- if boardType[3][0] == " " and not checkCheck((5,0),boardType,boardOwner) and boardType[2][0] == " " and not checkCheck((2,0),boardType,boardOwner) and boardType[1][0] == " ":
- return "whiteQueenSide"
- else:
- if (endx, endy) == (6, 7) and "M" not in kingSideCastle:
- if boardType[5][7] == " " and not checkCheck((5,7),boardType,boardOwner) and boardType[6][7] == " " and not checkCheck((6,7),boardType,boardOwner):
- return "blackKingSide"
- elif (endx, endy) == (2, 7) and "M" not in queenSideCastle:
- if boardType[3][7] == " " and not checkCheck((5,7),boardType,boardOwner) and boardType[2][7] == " " and not checkCheck((2,7),boardType,boardOwner) and boardType[1][7] == " ":
- return "blackQueenSide"
- if (endx, endy) in validMoves:
- return True
- else:
- print("Te ei saa sinna käia.")
- return False
- def castle(x): ########## Vangerdamise laua muutmine
- if x == "whiteKingSide":
- boardType[5][0] = "V"
- boardOwner[5][0] = "V"
- boardType[7][0] = " "
- boardOwner[7][0] = " "
- boardType[6][0] = "K"
- boardOwner[6][0] = "V"
- boardType[4][0] = " "
- boardOwner[4][0] = " "
- kingSideCastle.append("V")
- queenSideCastle.append("V")
- elif x == "blackKingSide":
- boardType[5][7] = "V"
- boardOwner[5][7] = "M"
- boardType[7][7] = " "
- boardOwner[7][7] = " "
- boardType[6][7] = "K"
- boardOwner[6][7] = "M"
- boardType[4][7] = " "
- boardOwner[4][7] = " "
- kingSideCastle.append("M")
- queenSideCastle.append("M")
- elif x == "whiteQueenSide":
- print("x")
- boardType[3][0] = "V"
- boardOwner[3][0] = "V"
- boardType[0][0] = " "
- boardOwner[0][0] = " "
- boardType[2][0] = "K"
- boardOwner[2][0] = "V"
- boardType[4][0] = " "
- boardOwner[4][0] = " "
- kingSideCastle.append("V")
- queenSideCastle.append("V")
- elif x == "blackQueenSide":
- boardType[3][7] = "V"
- boardOwner[3][7] = "M"
- boardType[0][7] = " "
- boardOwner[0][7] = " "
- boardType[2][7] = "K"
- boardOwner[2][7] = "M"
- boardType[4][7] = " "
- boardOwner[4][7] = " "
- kingSideCastle.append("M")
- queenSideCastle.append("M")
- def pawnUpgrade(endPos):
- while True:
- command = input("What piece would you like your pawn to be upgraded to [Q/R/B/N]? ")
- if len(command) != 0:
- command = typeToEE(command[0])
- if len(command) == 1 and command[0].upper() in "L O V R".split():
- boardType[endPos[0]][endPos[1]] = command[0].upper()
- return
- def changeBoard(turn, startPos, endPos):
- if boardType[endPos[0]][endPos[1]] == "K":
- if turn == "V":
- print("White wins.")
- else:
- print("Black wins.")
- return False
- boardType[endPos[0]][endPos[1]] = boardType[startPos[0]][startPos[1]]
- boardOwner[endPos[0]][endPos[1]] = turn
- boardType[startPos[0]][startPos[1]] = " "
- boardOwner[startPos[0]][startPos[1]] = " "
- # Vankri liikumine
- if boardType[endPos[0]][endPos[1]] == "V":
- if startPos == (0,0):
- queenSideCastle.append("V")
- elif startPos == (0,7):
- queenSideCastle.append("M")
- elif startPos == (7,0):
- kingSideCastle.append("V")
- elif startPos == (7,7):
- kingSideCastle.append("M")
- if turn == "V": #Etturite ülendamine mängulaua lõppu jõudes
- if boardType[endPos[0]][endPos[1]] == "E" and endPos[1] == 7:
- pawnUpgrade(endPos)
- else:
- if boardType[endPos[0]][endPos[1]] == "E" and endPos[1] == 0:
- pawnUpgrade(endPos)
- if boardType[endPos[0]][endPos[1]] == "K": #Kuninga liikumine
- if turn == "V":
- kingSideCastle.append("V")
- queenSideCastle.append("V")
- whiteKingPos = (endPos[0],endPos[1])
- else:
- kingSideCastle.append("M")
- queenSideCastle.append("M")
- blackKingPos = (endPos[0],endPos[1])
- return True
- def moveStage(turn):
- while True:
- startPos, endPos, surrender = getMove(turn)
- if surrender == 1:# alla andmine
- if turn == "V":
- print("White has surrendered.")
- else:
- print("Black has surrendered.")
- return False
- temp = checkValidity (turn, startPos, endPos)
- if temp != True and temp != False:
- castle(temp)
- return True
- elif temp:
- if changeBoard(turn, startPos, endPos): #returni false kui kuningas võeti ära
- return True
- else:
- return False
- def playAgain():
- while True:
- command = input("Would you like to play again? (j/e): ") #Jah
- if len(command)==0:
- nope = ".avi"
- elif command[0].lower() == "j":
- return True
- elif command[0].lower() == "e":
- return False
- def showTurn(turn, pointsWhite, pointsBlack):
- if turn == "V":
- print("White's turn. Points: %s" %(pointsWhite))
- else:
- print("Black's turn. Points: %s" %(pointsBlack))
- print("")
- def displayTutorial(): #TutorialTexti pikkus ei tohi jaguda selle jagatava arvuga (praegu 70)
- tutorialText = "Only available in the Estonian version."
- print("-------------------------------------------------------------------------")
- for x in range(len(textwrap.wrap(tutorialText))):
- print(textwrap.wrap(tutorialText)[x])
- print("-------------------------------------------------------------------------")
- def enterToStart():
- input("Press Enter to begin.")
- def displayStart():
- print("SmartChess(c) 2014 Beta 1.5.1")
- print("Copyright: J.Kirme and A.Saidlo")
- def displayOptions(printMode, purchasing, placing, queens, check):
- print("{0:30}".format("Board size (S - large, K - medium, V - small): ") + printMode)
- if check:
- print ("{0:30}".format("Check:") + "On")
- else:
- print ("{0:30}".format("Check:") + "Off")
- if purchasing:
- print ("{0:30}".format("Purchasing pieces:") + "On")
- else:
- print ("{0:30}".format("Purchasing pieces:") + "Off")
- if placing == "M":
- print ("{0:30}".format("Purchasing location:") + "Back row and promotion")
- elif placing == "T":
- print ("{0:30}".format("Purchasing location:") + "Back row")
- elif placing == "P":
- print ("{0:30}".format("Purchasing location:") + "Promotion")
- if queens:
- print ("{0:30}".format("Purchasing queens:") + "On")
- else:
- print ("{0:30}".format("Purchasing queens:") + "Off")
- def changeOptions(printMode, purchasing, placing, queens, check):
- while True:
- print("-------------------------------------------------------------------------")
- displayOptions(printMode, purchasing, placing, queens, check)
- print("-------------------------------------------------------------------------")
- print("Which option would you like to change? ")
- command = input("Size[S]/Check[U]/Purchasing[O]/Location[A]/Queens[L]/Back[T] ")
- if len(command)==0: #Miks ma neid ei kirjutanud if len!=0? -J
- nope = ".avi"
- elif command[0].upper() == "S":
- printMode = getPrintMode()
- elif command[0].upper() == "O":
- if purchasing == True:
- purchasing = False
- else:
- purchasing = True
- elif command[0].upper() == "A":
- while True:
- placing = input("What should the possible placement of purchasing be like? (Back row[T]/Promotion[P]/Both[M]) ")
- if len(placing) != 0:
- placing = placing[0].upper()
- if placing in ("T","P","M"):
- break
- else:
- print("That's not a valid input. ")
- elif command[0].upper() == "L":
- if queens == True:
- queens = False
- else:
- queens = True
- elif command[0].upper() == "U":
- if check == True:
- check = False
- else:
- check = True
- elif command[0].upper() == "T":
- break
- return printMode, purchasing, placing, queens
- def startMenu(printMode, purchasing, placing, queens, check):
- while True:
- command = input("Would you like to start[A] or open the options menu[V]? ")
- if len(command)==0:
- nope = ".avi"
- elif command[0].upper() == "A":
- return printMode, purchasing, placing, queens
- elif command[0].upper() == "J":
- displayTutorial()
- elif command[0].upper() == "V":
- printMode, purchasing, placing, queens = changeOptions(printMode, purchasing, placing, queens, check)
- def shop(turn, pointsWhite, pointsBlack, pawnValue, placing):
- R = 0
- validPlaces = []
- printBoard(printMode)
- if turn == "V":
- points = pointsWhite
- else:
- points = pointsBlack
- while True:
- pood = (input("Would you like to purchase a new piece?[J/E] "))
- if len(pood) != 0:
- pood = pood[0].upper()
- if pood in ("E","J"):
- break
- else:
- print("Palun jälgige õigeid sisestusreegleid. ")
- if pood == "J":
- print("-------------------------------------------------------------------------")
- print("{0:15}".format("Shop") + "Points:",points,"\n")
- if queens:
- print("{0:15}".format("Queen:"), 9*pawnValue)
- print("{0:15}".format("Rook:"), 5*pawnValue)
- print("{0:15}".format("Bishop/Knight:"), 3*pawnValue)
- print("-------------------------------------------------------------------------")
- while True:
- while True:
- if turn == "V":
- points = pointsWhite
- else:
- points = pointsBlack
- if queens:
- newPiece = input("What kind of piece would you like [Q/R/B/N]? Press [T] to go back. ")
- if len(newPiece) != 0:
- newPiece = newPiece[0].upper()
- newPiece = typeToEE(newPiece[0])
- if newPiece in ("L","O","R","V"):
- if newPiece == "L" and points >= 9*pawnValue:
- points -= 9*pawnValue
- break
- if newPiece == "V" and points >= 5*pawnValue:
- points -= 5*pawnValue
- break
- if newPiece == "O" and points >= 3*pawnValue:
- points -= 3*pawnValue
- break
- if newPiece == "R" and points >= 3*pawnValue:
- points -= 3*pawnValue
- break
- else:
- newPiece = input("What piece would you like [R/B/N]? Press [T] to go back. ")
- if len(newPiece) != 0:
- newPiece = newPiece[0].upper()
- newPiece = typeToEE(newPiece[0])
- if newPiece in ("O","R","V"):
- if newPiece == "V" and points >= 5*pawnValue:
- points -= 5*pawnValue
- break
- if newPiece == "O" and points >= 3*pawnValue:
- points -= 3*pawnValue
- break
- if newPiece == "R" and points >= 3*pawnValue:
- points -= 3*pawnValue
- break
- elif newPiece == "L":
- print("Buying queens is disabled.")
- if newPiece == "T":
- break
- else:
- print("Please insert a valid letter.")
- if newPiece == "T":
- break
- if turn == "V":
- backup = pointsWhite
- pointsWhite = points
- else:
- backup = pointsBlack
- pointsBlack = points
- if placing == "M" or placing == "T":
- if turn == "V":
- for i in range(8):
- if boardType[i][0] == " ":
- validPlaces.append((i,0))
- else:
- for i in range(8):
- if boardType[i][7] == " ":
- validPlaces.append((i,7))
- if placing == "M" or placing == "P":
- for i in range(8):
- for j in range(8):
- if boardOwner[i][j] == turn and boardType[i][j] != "K":
- validPlaces.append((i,j))
- while True:
- place = str(input("Where would you like to place your piece? [T] to cancel "))
- if len(place) != 0:
- if len(place) == 2 and place[0].upper() in LETTERSATOH and place[1] in DIGITS1TO8:
- place = str(place[0].upper()) + str(place[1])
- place = posConvert(place)
- if place in validPlaces:
- boardType[place[0]][place[1]] = newPiece
- boardOwner[place[0]][place[1]] = turn
- R = 1
- break
- if placing == "T" and boardOwner[place[0]][place[1]] == turn:
- print("Promotion isn't allowed.")
- elif placing == "P" and boardOwner[place[0]][place[1]] == " " and place[1] == 0:
- print("Only promotion is allowed.")
- elif boardType[place[0]][place[1]] == "K":
- print("You can't promote your king.")
- elif place[0].upper() == "T":
- if turn == "V":
- pointsWhite = backup
- else:
- pointsBlack = backup
- break
- else:
- print("Not a valid input.")
- if R == 1 or place == "T":
- break
- return boardType, boardOwner,pointsBlack,pointsWhite
- def getNewOperationMath():
- x = random.randint(100,999)#Liitmine
- y = random.randint(100,999)
- answerRight = str(x+y)
- operationDisplay = str(x) + "+" + str(y)
- pointsWorth = 1
- return answerRight, operationDisplay, pointsWorth
- def giveOperationMath(turn, pointsWhite, pointsBlack):
- answerRight, operationDisplay, pointsWorth = getNewOperationMath()
- if turn == "V":
- print("Points: %s" %pointsWhite)
- else:
- print("Points: %s" %pointsBlack)
- answerPlayer = input("%s = " %(operationDisplay))
- return answerRight, answerPlayer, pointsWorth
- def mathStage(turn, timeLast, pointsWhite, pointsBlack): #Veel whitespace'i
- print("")
- print("You have %s seconds to solve tasks." % (round(timeLast, 1)))
- print("")
- time.sleep(3)
- timeStart = timerStart()
- while True:
- if time.time() - timeStart > timeLast:
- break
- else:
- answerRight, answerPlayer, pointsWorth = giveOperationMath(turn, pointsWhite, pointsBlack)
- print("")
- if turn == "V":
- if answerRight == answerPlayer:
- pointsWhite += pointsWorth
- else:
- pointsWhite -= pointsWorth
- else:
- if answerRight == answerPlayer:
- pointsBlack += pointsWorth
- else:
- pointsBlack -= pointsWorth
- timeOverLimit = time.time()-timeStart-timeLast
- print("The opponent is given %s seconds for going over your time." %(round(timeOverLimit, 1)))
- return timeOverLimit, pointsWhite, pointsBlack
- def questionStage(turn, timeLast, questionLast, questionsBanned, pointsWhite, pointsBlack): #Lisa siit alates
- timeOverLimit = 0
- if timeLast == 0 and turn == "V":
- print("")
- print("You can't solve tasks on the first turn.")
- print("")
- elif questionLast == 0: #Must saab juba küsimuse 1. käigul
- while questionLast in questionsBanned:
- questionLast = random.randint(1,100)
- elif turn == "V": #Valge käigul tuleb uus voor
- while questionLast in questionsBanned:
- questionLast = random.randint(1,100)
- if questionLast > 0 and questionLast <= 100: #Pranglimine, vaheta tagasi 1-90 (kui EK töötab) #############################
- #print("Pranglimise voor.") ################################### Vaheta tagasi kui teisi voore tuleb
- timeOverLimit, pointsWhite, pointsBlack = mathStage(turn, timeLast, pointsWhite, pointsBlack)
- elif questionLast > 100: #Eesti keel. Vaheta tagasi 91-100 (kui see töötab) ##########################
- print("Eesti keele voor.")
- if turn == "V" and questionLast != 0:
- print("Points: %s" %(pointsWhite))
- elif questionLast != 0:
- print("Points: %s" %(pointsBlack))
- print("Turn change is imminent.")
- time.sleep(5)
- return timeOverLimit, pointsWhite, pointsBlack
- def timerStart():
- timeStart = time.time()
- return timeStart
- def timerEnd(timeStart):
- timeCurrent = time.time()-timeStart
- return timeCurrent
- def showTime(timeCurrent, timeLast):
- print("")
- print("You took %s seconds." %(round(timeCurrent, 1)))
- #if timeLast == 0: ######### Tundub, et see on mõttetu rida
- print("Questions are imminent.")
- time.sleep(2)
- displayStart()
- printMode = "K" #Keskmine suurus
- purchasing = True #Nuppude ostmine on sees
- queens = True #Lippe saab osta
- placing = "M"
- check = True
- questionsBanned = [0]
- pawnValue = 1
- while True:
- turn = "M"
- kingSideCastle = [] #Vangerduse kontroll
- queenSideCastle = []
- printMode, purchasing, placing, queens = startMenu(printMode, purchasing, placing, queens, check)
- boardType = getNewBoardType()
- boardOwner = getNewBoardOwner()
- enterToStart()
- pointsWhite = 0
- pointsBlack = 0
- timeLast = 0
- questionLast = 0
- blackKingPos = (4,7)
- whiteKingPos = (4,0)
- while True:
- turn = turnChange(turn)
- printBoard(printMode)
- if purchasing:
- timeStart = timerStart()
- showTurn(turn, pointsWhite, pointsBlack)
- if not moveStage(turn): #returni false kui kuningas võeti ära
- break
- if purchasing:
- boardType, BoardOwner, pointsBlack, pointsWhite = shop(turn, pointsWhite, pointsBlack, pawnValue, placing)
- timeCurrent = timerEnd(timeStart)
- showTime(timeCurrent, timeLast) #Oodata mõni sekund enne küsimuste esitamist
- timeOverLimit, pointsWhite, pointsBlack = questionStage(turn, timeLast, questionLast, questionsBanned, pointsWhite, pointsBlack)
- timeLast = timeCurrent + timeOverLimit
- if not playAgain():
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement