Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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("Sisestage malelaua kuvamise suurus (suur, keskmine, väike): ")
- 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
- 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("")
- 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("Sisestage oma käik: ")
- 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("Seal asukohas ei ole teie nuppu.")
- else:
- return startPos, endPos, surrender
- else:
- print("Sisestage oma käik formaadis [algasukoha täht][algasukoha number][sihtpunkti täht][sihtpunkti number]. Näiteks 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("Tuli! Te ei saa sinna käia.")
- return False
- elif turn == "V":
- if checkCheck(whiteKingPos,boardTypeTemp,boardOwnerTemp):
- print("Tuli! Te ei saa sinna käia.")
- return False
- else:
- if checkCheck(blackKingPos,boardTypeTemp,boardOwnerTemp):
- print("Tuli! Te ei saa sinna käia.")
- 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("Milliseks nupuks te tahate oma etturi uuendada [L/O/V/R]? ")
- 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("Valge võit.")
- else:
- print("Musta võit.")
- 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("Valge andis alla.")
- else:
- print("Must andis alla.")
- 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("Kas soovite uuesti mängida? (jah/ei): ") #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("Valge käik. Punkte: %s" %(pointsWhite))
- else:
- print("Musta käik. Punkte: %s" %(pointsBlack))
- print("")
- def displayTutorial(): #TutorialTexti pikkus ei tohi jaguda selle jagatava arvuga (praegu 70)
- tutorialText = "SmartChess on malemäng, kus saab iga käik mänguväliseid punkte ülesannete lahendamise eest. Pärast igat enda käiku saab osta olemasolevate punktide eest nuppe, mida saab lauale asetada. Nuppe saab kas osta enda kõige lähimale reale või asetada teiste nuppude asemele (valikuid saab sätete menüüst muuta). Mida kauem sa mõtled oma käikude ja nuppude ostmise üle, seda rohkem on su vastasel aega ülesannete lahendamiseks. Ülesannete lahendamisel loevad kõik vastused, kuid selle võrra, kui palju te ajast üle lähete, saab vastane oma ülesannete lahendamisel aega juurde. Pärast mängu alustamist pole pause, et ära hoida sohi tegemine. Malelaud on koordinaatteljestik, kus veerud on tähistatud tähtedega a-h ja read numbritega 1-8, kusjuures loendamine algab alt vasakust nurgast. Käigu sooritamiseks trükkige nelja-sümboliline kombinatsioon, kus esimesed kaks sümbolit on liigutatava nupu koordinaadid ja viimased kaks on sihtruudu koordinaadid, nt: Kirjutades E2E4 esimesel käigul, liigub valge ettur ruudul E2 ruutu E4. Nuppude tähised on: E - ettur, V - vanker, R - ratsu, O - oda, L - lipp, K - kuningas. Värve tähistatakse tähtedega V ja M. Malelaual on nupud tähistatud kahe tähega, kus esimene täht näitab tüüpi, teine värvi. Vahel küsitakse teilt küsimus, mille lõpus on sõnad, mille esimesed tähed on nurksulgudes (näiteks [L]ipp). Need sõnad on vastusevariandid. Sellises olukorras peate teadma, et endale sobiva variandi tegemiseks peate sisestama ühe sulgudes olevatest tähtedest."
- print("-------------------------------------------------------------------------")
- for x in range(len(textwrap.wrap(tutorialText))):
- print(textwrap.wrap(tutorialText)[x])
- print("-------------------------------------------------------------------------")
- def enterToStart():
- input("Vajutage enter, et mäng algaks.")
- def displayStart():
- print("SmartChess(c) 2014 Beta 1.5.1")
- print("Copyright: J.Kirme and A.Saidlo")
- print("Kui mängite esimest korda, on soovitatud juhendit lugeda.")
- def displayOptions(printMode, purchasing, placing, queens, check):
- print("{0:30}".format("Laua kuvamise suurus:") + printMode)
- if check:
- print ("{0:30}".format("Tuli:") + "Sees")
- else:
- print ("{0:30}".format("Tuli:") + "Väljas")
- if purchasing:
- print ("{0:30}".format("Uute nuppude ostmine:") + "Sees")
- else:
- print ("{0:30}".format("Uute nuppude ostmine:") + "Väljas")
- if placing == "M":
- print ("{0:30}".format("Nuppude asetamine:") + "Mõlemad")
- elif placing == "T":
- print ("{0:30}".format("Nuppude asetamine:") + "Tagumine rida")
- elif placing == "P":
- print ("{0:30}".format("Nuppude asetamine:") + "Promotion")
- if queens:
- print ("{0:30}".format("Lippude ostmine:") + "Sees")
- else:
- print ("{0:30}".format("Lippude ostmine:") + "Väljas")
- def changeOptions(printMode, purchasing, placing, queens, check):
- while True:
- print("-------------------------------------------------------------------------")
- displayOptions(printMode, purchasing, placing, queens, check)
- print("-------------------------------------------------------------------------")
- print("Millist valikut soovite muuta? ")
- command = input("[S]uurus/T[u]li/[O]stmine/[A]setamine/[L]ipud/[T]agasi ")
- 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("Milline peaks olema uute nuppude asetamine? ([T]agumine rida/[P]romotion/[M]õlemad) ")
- if len(placing) != 0:
- placing = placing[0].upper()
- if placing in ("T","P","M"):
- break
- else:
- print("Palun jälgige õigeid sisestusreegleid. ")
- 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("Kas soovite [A]lustada, [J]uhendit näha või [V]alikuid muuta? ")
- 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("Kas soovite uue nupu osta?[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:10}".format("Pood") + "Punktid:",points,"\n")
- if queens:
- print("{0:10}".format("Lipp:"), 9*pawnValue)
- print("{0:10}".format("Vanker:"), 5*pawnValue)
- print("{0:10}".format("Oda/Ratsu:"), 3*pawnValue)
- print("-------------------------------------------------------------------------")
- while True:
- while True:
- if turn == "V": ############# Siia lisasin
- points = pointsWhite
- else:
- points = pointsBlack
- if queens:
- newPiece = input("Millist nuppu soovite osta? ([L]ipp, [O]da, [R]atsu, [V]anker, [T]ühista) ")
- if len(newPiece) != 0:
- newPiece = newPiece[0].upper()
- 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("Millist nuppu soovite osta? ([O]da, [R]atsu, [V]vanker, [T]ühista) ")
- if len(newPiece) != 0:
- newPiece = newPiece[0].upper()
- 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("Lipud on keelatud.")
- if newPiece == "T":
- break
- else:
- print("Palun sisestage korrektne nuputähis.")
- 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("Kuhu soovite oma nupu asetada?([T]ühista kui muutsite meelt) "))
- 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 pole lubatud.")
- elif placing == "P" and boardOwner[place[0]][place[1]] == " " and place[1] == 0:
- print("Lubatud on ainult promotion.")
- elif boardType[place[0]][place[1]] == "K":
- print("Sa ei saa kuningat promotida :)")
- elif place[0].upper() == "T":
- if turn == "V":
- pointsWhite = backup
- else:
- pointsBlack = backup
- break
- else:
- print("Pole korrektne sisend.")
- 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("Punkte: %s" %pointsWhite)
- else:
- print("Punkte: %s" %pointsBlack)
- answerPlayer = input("%s = " %(operationDisplay))
- return answerRight, answerPlayer, pointsWorth
- def mathStage(turn, timeLast, pointsWhite, pointsBlack): #Veel whitespace'i
- print("")
- print("Teil on %s sekundit aega ülesannete lahendamiseks." % (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("Vastasele antakse aega %s sekundit ajalimiidi ületamise eest." %(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("Esimesel käigul ei saa ülesandeid lahendada.")
- 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("Punkte: %s" %(pointsWhite))
- elif questionLast != 0:
- print("Punkte: %s" %(pointsBlack))
- print("Käigu vahetus mõne hetke pärast.")
- 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("Teil kulus %s sekundit." %(round(timeCurrent, 1)))
- #if timeLast == 0: ######### Tundub, et see on mõttetu rida
- print("Kohe algavad küsimused.")
- 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