Guest User

SmartChess beta 1.3

a guest
Oct 6th, 2014
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 24.88 KB | None | 0 0
  1. import time
  2. import random
  3. import operator
  4.  
  5. DIGITS1TO8 = "1 2 3 4 5 6 7 8".split()
  6. LETTERSATOH = "A B C D E F G H".split()
  7.  
  8. def getNewBoardType():
  9.     boardType = [[" "] * 8 for i in range(8)]
  10.     for x in range(8):
  11.         boardType[x][1] = "E"
  12.         boardType[x][6] = "E"
  13.     typeOrder = ["V", "R", "O", "L", "K", "O", "R", "V"]
  14.     for x in range(8):
  15.         boardType[x][0] = typeOrder[x]
  16.         boardType[x][7] = typeOrder[x]
  17.     return boardType
  18.  
  19. def getNewBoardOwner():
  20.     boardOwner = [[" "] * 8 for i in range(8)]
  21.     for x in range(8):
  22.         boardOwner[x][1] = "V"
  23.         boardOwner[x][0] = "V"
  24.         boardOwner[x][6] = "M"
  25.         boardOwner[x][7] = "M"
  26.     return boardOwner
  27.  
  28. def getPrintMode():
  29.     while True:
  30.         printMode = input("Sisestage malelaua kuvamise suurus (suur, keskmine, väike): ")
  31.         if len(printMode)==0:
  32.             nope = ".avi"
  33.         elif printMode[0].upper()=="S":
  34.             printMode = "S"
  35.             break
  36.         elif printMode[0].upper()=="V":
  37.             printMode = "V"
  38.             break
  39.         elif printMode[0].upper()=="K":
  40.             printMode = "K"
  41.             break
  42.     return printMode
  43.  
  44. def printBoard(printMode):
  45.     if printMode == "S":
  46.         print("  ", end="")
  47.         for x in range(8):
  48.             print("    %s    " %(LETTERSATOH[x]), end="")
  49.         print("")
  50.         for y in range(8):
  51.             print("  "+"+--------"*8, end="")
  52.             print("+")
  53.             print("  "+"|        "*8+"|")
  54.             print(DIGITS1TO8[7-y], end = " ")
  55.             for x in range(8):
  56.                 print("|   %s%s   " %(boardType[x][7-y], boardOwner[x][7-y]), end = "")
  57.             print("|  ", end = " ")
  58.             print(DIGITS1TO8[7-y])
  59.             print("  ", end="")
  60.             for x in range(8):
  61.                 print("|%s%s      " % (LETTERSATOH[x],DIGITS1TO8[8-y-1]), end = "")
  62.             print("|")
  63.         print("  "+"+--------"*8, end="")
  64.         print("+")
  65.         print("  ", end="")
  66.         for x in range(8):
  67.             print("    %s    " %(LETTERSATOH[x]), end="")
  68.         print("")
  69.        
  70.     elif printMode == "V":
  71.         print("  ", end="")
  72.         for x in range(8):
  73.             print("  %s " %(LETTERSATOH[x]), end="")
  74.         print("")
  75.         for y in range(8):
  76.             print("  "+"+---"*8, end="")
  77.             print("+")
  78.             print(DIGITS1TO8[7-y], end = " ")
  79.             for x in range(8):
  80.                 print("|%s%s " %(boardType[x][7-y], boardOwner[x][7-y]), end = "")
  81.             print("|", end = " ")
  82.             print(DIGITS1TO8[7-y])
  83.         print("  "+"+---"*8, end="")
  84.         print("+")
  85.         print("  ", end="")
  86.         for x in range(8):
  87.             print("  %s " %(LETTERSATOH[x]), end="")
  88.         print("")
  89.        
  90.     elif printMode == "K":
  91.         print("  ", end="")
  92.         for x in range(8):
  93.             print("  %s  " %(LETTERSATOH[x]), end="")
  94.         print("")
  95.         for y in range(8):
  96.             print("  "+"+----"*8, end="")
  97.             print("+")
  98.             print(DIGITS1TO8[7-y], end = " ")
  99.             for x in range(8):
  100.                 print("| %s%s " %(boardType[x][7-y], boardOwner[x][7-y]), end = "")
  101.             print("|", end = " ")
  102.             print(DIGITS1TO8[7-y])
  103.         print("  "+"+----"*8, end="")
  104.         print("+")
  105.         print("  ", end="")
  106.         for x in range(8):
  107.             print("  %s  " %(LETTERSATOH[x]), end="")
  108.         print("")
  109.        
  110.  
  111. def turnChange(turn):
  112.     if turn == "V":
  113.         turn = "M"
  114.     else:
  115.         turn = "V"
  116.     return turn
  117.  
  118. def posConvert(position):
  119.     position = ((ord(position[0])-ord("A")), int(position[1])-1)
  120.     return position
  121.  
  122. def getMove(turn):
  123.     while True:
  124.         surrender = 0
  125.         movesTogether = input("Sisestage oma käik: ")
  126.         if movesTogether.lower() == "surrender": #Alla andmine
  127.             surrender = 1
  128.             startPos = (0,0)
  129.             endPos = (0,0)
  130.             return startPos, endPos, surrender
  131.         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:
  132.             startPos = str(movesTogether[0].upper()) + movesTogether[1]
  133.             endPos = str(movesTogether[2].upper()) + movesTogether[3]
  134.             startPos = posConvert(startPos)
  135.             endPos = posConvert(endPos)
  136.             if boardOwner[startPos[0]][startPos[1]] != turn:
  137.                 print("Seal asukohas ei ole teie nuppu.")
  138.             else:
  139.                 return startPos, endPos, surrender
  140.         else:
  141.             print("Sisestage oma käik formaadis [algasukoha täht][algasukoha number][sihtpunkti täht][sihtpunkti number]. Näiteks A2A3.")
  142.  
  143. def checkValidity(turn, startPos, endPos):
  144.     validMoves = []
  145.     startx = startPos[0]
  146.     starty = startPos[1]
  147.     endx = endPos[0]
  148.     endy = endPos[1]
  149.     if boardType[startx][starty] == "E": #Lisab validMoves listi kõik võimalikud käigud etturi poolt.
  150.         if turn == "V":
  151.             if boardType[startx][starty+1] == " ":
  152.                 validMoves.append((startx,starty+1))
  153.             if startx+1 < 8 and boardOwner[startx+1][starty+1] == "M":
  154.                 validMoves.append((startx+1,startPos[1]+1))
  155.             if startx-1 > -1 and boardOwner[startx-1][starty+1] == "M":
  156.                 validMoves.append((startx-1,starty+1))
  157.             if starty == 1 and boardType[startx][starty+2] == " ":
  158.                 validMoves.append((startx,3))
  159.         if turn == "M":
  160.             if boardType[startx][starty-1] == " ":
  161.                 validMoves.append((startx,starty-1))
  162.             if startx+1 < 8 and boardOwner[startx+1][starty-1] == "V":
  163.                 validMoves.append((startx+1,starty-1))
  164.             if startx-1 > -1 and boardOwner[startx-1][starty-1] == "V":
  165.                 validMoves.append((startx-1,starty-1))
  166.             if starty == 6 and boardType[startx][starty-2] == " ":
  167.                 validMoves.append((startx,4))
  168.                
  169.     if boardType[startx][starty] == "K":
  170.         if startx-1 > -1 and (boardOwner[startx-1][starty] != turn):
  171.             validMoves.append((startx-1,starty))
  172.         if startx+1 < 8 and (boardOwner[startx-1][starty] != turn):
  173.             validMoves.append((startx+1,starty))
  174.         if starty+1 < 8:
  175.             for i in range(3):
  176.                 if startx-1+i < 8 and startx-1+i > - 1:
  177.                     if boardOwner[startx-1+i][starty+1] != turn:
  178.                         validMoves.append((startx-1+i,starty+1))
  179.         if starty-1 > -1:
  180.             for i in range(3):
  181.                 if startx-1+i < 8 and startx-1+i > - 1:
  182.                     if boardOwner[startx-1+i][starty-1] != turn:
  183.                         validMoves.append((startx-1+i,starty-1))
  184.  
  185.     if boardType[startx][starty] == "R":
  186.         if starty+2 < 8:
  187.             if startx-1 > -1:
  188.                 if boardOwner[startx-1][starty+2] != turn:
  189.                     validMoves.append((startx-1,starty+2))
  190.             if startx+1 < 8:
  191.                 if boardOwner[startx+1][starty+2] != turn:
  192.                     validMoves.append((startx+1,starty+2))
  193.         if starty-2 > -1:
  194.             if startx-1 > -1:
  195.                 if boardOwner[startx-1][starty-2] != turn:
  196.                     validMoves.append((startx-1,starty-2))
  197.             if startx+1 < 8:
  198.                 if boardOwner[startx+1][starty-2] != turn:
  199.                     validMoves.append((startx+1,starty-2))
  200.         if startx+2 < 8:
  201.             if starty-1 > -1:
  202.                 if boardOwner[startx+2][starty-1] != turn:
  203.                     validMoves.append((startx+2,starty-1))
  204.             if starty+1 < 8:
  205.                 if boardOwner[startx+2][starty+1] != turn:
  206.                     validMoves.append((startx+2,starty+1))
  207.         if startx-2 > -1 :
  208.             if starty-1 > -1:
  209.                 if boardOwner[startx-2][starty-1] != turn:
  210.                     validMoves.append((startx-2,starty-1))
  211.             if starty+1 < 8:
  212.                 if boardOwner[startx-2][starty+1] != turn:
  213.                     validMoves.append((startx-2,starty+1))
  214.  
  215.     if boardType[startx][starty] == "V" or boardType[startx][starty] == "L":
  216.         for moveLength in range(1,8):
  217.             if starty+moveLength < 8: #1. Üles
  218.                 nextTileNumber = (startx, (starty+moveLength))
  219.                 nextTileOwner = boardOwner[startx][starty+moveLength]
  220.                 if nextTileOwner != turn:
  221.                     if nextTileOwner == " ":
  222.                         validMoves.append(nextTileNumber)
  223.                     else:
  224.                         validMoves.append(nextTileNumber)
  225.                         break
  226.                 else:
  227.                     break
  228.         for moveLength in range(1,8):
  229.             if startx+moveLength < 8: #2. Paremale
  230.                 nextTileNumber = (startx+moveLength, starty)
  231.                 nextTileOwner = boardOwner[startx+moveLength][starty]
  232.                 if nextTileOwner != turn:
  233.                     if nextTileOwner == " ":
  234.                         validMoves.append(nextTileNumber)
  235.                     else:
  236.                         validMoves.append(nextTileNumber)
  237.                         break
  238.                 else:
  239.                     break
  240.         for moveLength in range(1,8):
  241.             if starty-moveLength > (-1): #3. Alla
  242.                 nextTileNumber = (startx, starty-moveLength)
  243.                 nextTileOwner = boardOwner[startx][starty-moveLength]
  244.                 if nextTileOwner != turn:
  245.                     if nextTileOwner == " ":
  246.                         validMoves.append(nextTileNumber)
  247.                     else:
  248.                         validMoves.append(nextTileNumber)
  249.                         break
  250.                 else:
  251.                     break
  252.         for moveLength in range(1,8):
  253.             if startx-moveLength > (-1): #4. Vasakule
  254.                 nextTileNumber = (startx-moveLength, starty)
  255.                 nextTileOwner = boardOwner[startx-moveLength][starty]
  256.                 if nextTileOwner != turn:
  257.                     if nextTileOwner == " ":
  258.                         validMoves.append(nextTileNumber)
  259.                     else:
  260.                         validMoves.append(nextTileNumber)
  261.                         break
  262.                 else:
  263.                     break
  264.     if boardType[startx][starty] == "O" or boardType[startx][starty] == "L":
  265.         for moveLength in range(1,8): #1. asimuut 45
  266.             if startx+moveLength < 8 and starty+moveLength < 8:
  267.                 nextTileNumber = (startx+moveLength, starty+moveLength)
  268.                 nextTileOwner = boardOwner[startx+moveLength][starty+moveLength]
  269.                 if nextTileOwner != turn:
  270.                     if nextTileOwner == " ":
  271.                         validMoves.append(nextTileNumber)
  272.                     else:
  273.                         validMoves.append(nextTileNumber)
  274.                         break
  275.                 else:
  276.                     break
  277.         for moveLength in range(1,8): #2. asimuut 135
  278.             if startx+moveLength < 8 and starty-moveLength > (-1):
  279.                 nextTileNumber = (startx+moveLength, starty-moveLength)
  280.                 nextTileOwner = boardOwner[startx+moveLength][starty-moveLength]
  281.                 if nextTileOwner != turn:
  282.                     if nextTileOwner == " ":
  283.                         validMoves.append(nextTileNumber)
  284.                     else:
  285.                         validMoves.append(nextTileNumber)
  286.                         break
  287.                 else:
  288.                     break
  289.         for moveLength in range(1,8): #1. asimuut 225
  290.             if startx-moveLength > (-1) and starty-moveLength > (-1):
  291.                 nextTileNumber = (startx-moveLength, starty-moveLength)
  292.                 nextTileOwner = boardOwner[startx-moveLength][starty-moveLength]
  293.                 if nextTileOwner != turn:
  294.                     if nextTileOwner == " ":
  295.                         validMoves.append(nextTileNumber)
  296.                     else:
  297.                         validMoves.append(nextTileNumber)
  298.                         break
  299.                 else:
  300.                     break
  301.         for moveLength in range(1,8): #1. asimuut 315
  302.             if startx+moveLength > (-1) and starty+moveLength < 8:
  303.                 nextTileNumber = (startx-moveLength, starty+moveLength)
  304.                 nextTileOwner = boardOwner[startx-moveLength][starty+moveLength]
  305.                 if nextTileOwner != turn:
  306.                     if nextTileOwner == " ":
  307.                         validMoves.append(nextTileNumber)
  308.                     else:
  309.                         validMoves.append(nextTileNumber)
  310.                         break
  311.                 else:
  312.                     break
  313.     if (endx, endy) in validMoves:
  314.         return True
  315.     else:
  316.         print("Te ei saa sinna käia.")
  317.         return False
  318.  
  319. def changeBoard(turn, startPos, endPos):
  320.     if boardType[endPos[0]][endPos[1]] == "K":
  321.         if turn == "V":
  322.             print("Valge võit.")
  323.         else:
  324.             print("Musta võit.")
  325.         return False
  326.     boardType[endPos[0]][endPos[1]] = boardType[startPos[0]][startPos[1]]
  327.     boardOwner[endPos[0]][endPos[1]] = turn
  328.     boardType[startPos[0]][startPos[1]] = " "
  329.     boardOwner[startPos[0]][startPos[1]] = " "
  330.     return True
  331.  
  332. def moveStage(turn):
  333.     while True:
  334.         startPos, endPos, surrender = getMove(turn)
  335.         if surrender == 1:# alla andmine
  336.             if turn == "V":
  337.                 print("Valge andis alla.")
  338.             else:
  339.                 print("Must andis alla.")
  340.             return False
  341.         if checkValidity (turn, startPos, endPos):
  342.             if changeBoard(turn, startPos, endPos): #returni false kui kuningas võeti ära
  343.                 return True
  344.             else:
  345.                 return False
  346.  
  347. def playAgain():
  348.     while True:
  349.         command = input("Kas soovite uuesti mängida? (jah/ei): ") #Jah
  350.         if len(command)==0:
  351.             nope = ".avi"
  352.         elif command[0].lower() == "j":
  353.             return True
  354.         elif command[0].lower() == "e":
  355.             return False
  356.  
  357. def showTurn(turn):
  358.     if turn == "V":
  359.         print("Valge käik.")
  360.     else:
  361.         print("Musta käik.")
  362.  
  363. def displayTutorial():
  364.     print("-------------------------------------------------------------------------")
  365.     print("SmartChess on malemäng, kus saab iga käik mänguväliseid punkte ülesannete lahendamise eest.")
  366.     print("Pärast igat enda käiku saab osta olemasolevate punktide eest nuppe, mida saab lauale asetada, osta.") #Täiendada juhendit
  367.     print("Mida kauem sa mõtled oma käikude ja nuppude ostmise üle, seda rohkem on su vastasel aega ülesannete lahendamiseks.")
  368.     print("Malelaud on koordinaatteljestik, kus veerud on tähistatud tähtedega a-h")
  369.     print("ja veerud numbritega 1-8, kusjuures loendamine algab alt vasakust nurgast.")
  370.     print("Käigu sooritamiseks trükkige nelja-sümboliline kombinatsioon, kus esimesed kaks sümbolit on liigutatava nupu koordinaadid")
  371.     print("ja viimased kaks on sihtruudu koordinaadid, nt: Kirjutades E2E4 esimesel käigul, liigub valge ettur ruudul E2 ruutu E4.")
  372.     print("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.")
  373.     print("Malelaual on nupud tähistatud kahe tähega, kus esimene täht näitab tüüpi, teine värvi.")
  374.     print("Vahel küsitakse teilt küsimus, mille lõpus on sõnad, mille esimesd tähed on nurksulgudes (näiteks [L]ipp).")
  375.     print("Need sõnad on vastusevariandid.")
  376.     print("Sellises olukorras peate teadma, et endale sobiva variandi tegemiseks peate sisestama ühe sulgudes olevatest tähtedest.")
  377.     print("-------------------------------------------------------------------------")
  378.    
  379. def enterToStart():
  380.     input("Vajutage enter, et mäng algaks.")
  381.  
  382. def displayStart():
  383.     print("SmartChess(c) 2014 Beta 1.3")
  384.     print("Copyright: J.Kirme and A.Saidlo")
  385.  
  386. def displayOptions(printMode, purchasing, placing, queens):
  387.     print("{0:30}".format("Laua kuvamise suurus:") + printMode)
  388.     if purchasing:
  389.         print ("{0:30}".format("Uute nuppude ostmine:") + "Sees")
  390.     else:
  391.         print ("{0:30}".format("Uute nuppude ostmine:") + "Väljas")
  392.     if placing == "M":
  393.         print ("{0:30}".format("Nuppude asetamine:") + "Mõlemad")
  394.     elif placing == "T":
  395.         print ("{0:30}".format("Nuppude asetamine:") + "Tagumine rida")
  396.     elif placing == "P":
  397.         print ("{0:30}".format("Nuppude asetamine:") + "Promotion")      
  398.     if queens:
  399.         print ("{0:30}".format("Lippude ostmine:") + "Sees")
  400.     else:
  401.         print ("{0:30}".format("Lippude ostmine:") + "Väljas")
  402.  
  403. def changeOptions(printMode, purchasing, placing, queens):
  404.     while True:
  405.         print("-------------------------------------------------------------------------")
  406.         displayOptions(printMode, purchasing, placing, queens)
  407.         print("-------------------------------------------------------------------------")
  408.         print("Millist valikut soovite muuta? ")
  409.         command = input("[S]uurus/[O]stmine/[A]setamine/[L]ipud/[T]agasi ")
  410.         if len(command)==0:
  411.             nope = ".avi"
  412.         elif command[0].upper() == "S":
  413.             printMode = getPrintMode()
  414.         elif command[0].upper() == "O":
  415.             if purchasing == True:
  416.                 purchasing = False
  417.             else:
  418.                 purchasing = True
  419.         elif command[0].upper() == "A":
  420.             while True:
  421.                 placing = input("Milline peaks olema uute nuppude asetamine? ([T]agumine rida/[P]romotion/[M]õlemad) ")
  422.                 if len(placing) != 0:
  423.                     placing = placing[0].upper()
  424.                     if placing in ("T","P","M"):
  425.                         break
  426.                 else:
  427.                     print("Palun jälgige õigeid sisestusreegleid. ")
  428.         elif command[0].upper() == "L":
  429.             if queens == True:
  430.                 queens = False
  431.             else:
  432.                 queens = True
  433.         elif command[0].upper() == "T":
  434.             break
  435.     return printMode, purchasing, placing, queens
  436.  
  437. def startMenu(printMode, purchasing, placing, queens):
  438.     while True:
  439.         command = input("Kas soovite [A]lustada, [J]uhendit näha või [V]alikuid muuta? ")
  440.         if len(command)==0:
  441.             nope = ".avi"
  442.         elif command[0].upper() == "A":
  443.             return printMode, purchasing, placing, queens
  444.         elif command[0].upper() == "J":
  445.             displayTutorial()
  446.         elif command[0].upper() == "V":
  447.             printMode, purchasing, placing, queens = changeOptions(printMode, purchasing, placing, queens)
  448.  
  449. pawnValue = 1
  450. pointsWhite = 200 #AJUTISED TESTMUUTUJAD
  451. pointsBlack = 200
  452. def shop(turn, pointsWhite, pointsBlack, pawnValue, placing):
  453.     R = 0    
  454.     validPlaces = []
  455.     printBoard(printMode)
  456.     if turn == "V":
  457.         points = pointsWhite
  458.     else:
  459.         points = pointsBlack
  460.     while True:
  461.         pood = (input("Kas soovite uue nupu osta?[J/E] "))
  462.         if len(pood) != 0:
  463.             pood = pood[0].upper()
  464.             if pood in ("E","J"):
  465.                 break
  466.         else:
  467.             print("Palun jälgige õigeid sisestusreegleid. ")
  468.     if pood == "J":
  469.         print("-------------------------------------------------------------------------")
  470.         print("{0:10}".format("Pood") + "Punktid:",points,"\n")
  471.         if queens:
  472.             print("{0:10}".format("Lipp:"), 9*pawnValue)
  473.         print("{0:10}".format("Vanker:"), 5*pawnValue)
  474.         print("{0:10}".format("Oda/Ratsu:"), 3*pawnValue)
  475.         print("-------------------------------------------------------------------------")
  476.         while True:
  477.             while True:
  478.                 if queens:
  479.                     newPiece = input("Millist nuppu soovite osta? ([L]ipp, [O]da, [R]atsu, [V]vanker, [T]ühista) ")
  480.                     if len(newPiece) != 0:
  481.                         newPiece = newPiece[0].upper()
  482.                     if newPiece in ("L","O","R","V"):
  483.                         if newPiece == "L" and points >= 9*pawnValue:
  484.                             points -= 9*pawnValue
  485.                             break
  486.                         if newPiece == "V" and points >= 5*pawnValue:
  487.                             points -= 5*pawnValue
  488.                             break
  489.                         if newPiece == "O" and points >= 3*pawnValue:
  490.                             points -= 3*pawnValue
  491.                             break
  492.                         if newPiece == "R" and points >= 3*pawnValue:
  493.                             points -= 3*pawnValue
  494.                             break                    
  495.                 else:
  496.                     newPiece = input("Millist nuppu soovite osta? ([O]da, [R]atsu, [V]vanker, [T]ühista) ")
  497.                     if len(newPiece) != 0:
  498.                         newPiece = newPiece[0].upper()
  499.                     if newPiece in ("O","R","V"):                        
  500.                         if newPiece == "V" and points >= 5*pawnValue:
  501.                             points -= 5*pawnValue
  502.                             break
  503.                         if newPiece == "O" and points >= 3*pawnValue:
  504.                             points -= 3*pawnValue
  505.                             break
  506.                         if newPiece == "R" and points >= 3*pawnValue:
  507.                             points -= 3*pawnValue
  508.                             break
  509.                     elif newPiece == "L":
  510.                         print("Lipud on keelatud.")
  511.                
  512.                 if newPiece == "T":
  513.                     break
  514.                 else:
  515.                     print("Palun sisestage korrektne nuputähis.")
  516.             if newPiece == "T":
  517.                 break
  518.  
  519.             if turn == "V":
  520.                 backup = pointsWhite
  521.                 pointsWhite = points
  522.             else:
  523.                 backup = pointsBlack
  524.                 pointsBlack = points
  525.  
  526.            
  527.             if placing == "M" or placing == "T":
  528.                 if turn == "V":
  529.                     for i in range(8):
  530.                         if boardType[i][0] == " ":
  531.                             validPlaces.append((i,0))
  532.                 else:
  533.                     for i in range(8):
  534.                         if boardType[i][7] == " ":
  535.                             validPlaces.append((i,7))
  536.             if placing == "M" or placing == "P":
  537.                 for i in range(8):
  538.                     for j in range(8):
  539.                         if boardOwner[i][j] == turn and boardType[i][j] != "K":
  540.                             validPlaces.append((i,j))
  541.             while True:
  542.                 place = str(input("Kuhu soovite oma nupu asetada?([T]ühista kui muutsite meelt) "))
  543.                 if len(place) != 0:
  544.                    
  545.                     if len(place) == 2 and place[0].upper() in LETTERSATOH and place[1] in DIGITS1TO8:
  546.                         place = str(place[0].upper()) + str(place[1])
  547.                         place = posConvert(place)
  548.                         if place in validPlaces:
  549.                             boardType[place[0]][place[1]] = newPiece
  550.                             boardOwner[place[0]][place[1]] = turn
  551.                             R = 1
  552.                             break
  553.                         if placing == "T" and boardOwner[place[0]][place[1]] == turn:
  554.                             print("Promotion pole lubatud.")
  555.                         elif placing == "P" and boardOwner[place[0]][place[1]] == " " and place[1] == 0:
  556.                             print("Lubatud on ainult promotion.")
  557.                         elif boardType[place[0]][place[1]] == "K":
  558.                             print("Sa ei saa kuningat promotida :)")
  559.                    
  560.                     elif place[0].upper() == "T":
  561.                         if turn == "V":
  562.                             pointsWhite == backup
  563.                         else:
  564.                             pointsBlack == backup
  565.                         break
  566.                 else:
  567.                     print("Pole korrektne sisend.")
  568.             if R == 1 or place == "T":
  569.                 break        
  570.     return boardType, boardOwner,pointsBlack,pointsWhite    
  571.        
  572.        
  573.            
  574. displayStart()
  575. printMode = "K" #Keskmine suurus
  576. purchasing = True #Nuppude ostmine on sees
  577. queens = True #Lippe saab osta
  578. placing = "M"
  579.  
  580. while True:
  581.     turn = "M"
  582.     #Lisan options screeni -J
  583.     printMode, purchasing, placing, queens = startMenu(printMode, purchasing, placing, queens)
  584.     boardType = getNewBoardType()
  585.     boardOwner = getNewBoardOwner()
  586.     enterToStart()
  587.     while True:
  588.         turn = turnChange(turn)
  589.         printBoard(printMode)
  590.         showTurn(turn)        
  591.         if not moveStage(turn): #returni false kui kuningas võeti ära
  592.             break
  593.         if purchasing:
  594.             boardType, BoardOwner, pointsBlack, pointsWhite = shop(turn, pointsWhite, pointsBlack, pawnValue, placing)
  595.     if not playAgain():
  596.         break
Advertisement
Add Comment
Please, Sign In to add comment