def GetExpectedGameState(): promptMessage = ( "What gameState value do you expect in the response? \"\" for continue play" ) gameStateVal = utilities.GetUserInput(promptMessage, legalGameStates) gameState = ('"gameState": "' + gameStateVal + '"\n') # return a string return gameState
def GetCastlingMove(playerColor, moveList): # Determine castling notation here - Add castling move from algebraic chess notation as first list element # We have 2 possible castling moves for each playerColor side - 'kingSide' & 'queenSide' print("Castling move chosen.") move = "" promptMessage = ( "Which rook do you want to swap w/ your King - (Kingside ('k') or Queenside ('q')?" ) castlingSide = utilities.GetUserInput(promptMessage, legalCastlingSides) if castlingSide == "k": move = ("0-0") elif castlingSide == "q": move = ("0-0-0") else: print("Process ERROR - unknown castling move. Exiting.") sys.exit(1) # Since we know the playerColor and castlingside, add the original position King & rook Pieces #print("DEBUG: Our Castling move string list item came back as %s" % moveList) origRookPiece = {} origKingPiece = {} newRookPiece = {} newKingPices = () if playerColor == "w": if castlingSide == 'k': # Kingside (right) origRookPiece = utilities.MakePieceObj("R", "h1") origKingPiece = utilities.MakePieceObj("K", "e1") newRookPiece = utilities.MakePieceObj("R", "f1") newKingPiece = utilities.MakePieceObj("K", "g1") elif castlingSide == 'q': # Queenside (left) origRookPiece = utilities.MakePieceObj("R", "a1") origKingPiece = utilities.MakePieceObj("K", "e1") newRookPiece = utilities.MakePieceObj("R", "d1") newKingPiece = utilities.MakePieceObj("K", "c1") else: print( "Process ERROR - illegal castling notation found in move string : '%s'. Exiting...\n" % requestMoveString) sys.exit(1) if playerColor == "b": if castlingSide == 'k': # Kingside (right) origRookPiece = utilities.MakePieceObj("r", "h8") origKingPiece = utilities.MakePieceObj("k", "e8") newRookPiece = utilities.MakePieceObj("r", "f8") newKingPiece = utilities.MakePieceObj("k", "g8") elif castlingSide == 'q': # Queenside (left) origRookPiece = utilities.MakePieceObj("r", "a8") origKingPiece = utilities.MakePieceObj("k", "e8") newRookPiece = utilities.MakePieceObj("r", "d8") newKingPiece = utilities.MakePieceObj("k", "c8") else: print( "Process ERROR - illegal castling notation found in move string : '%s'. Exiting...\n" % requestMoveString) sys.exit(1) moveList = [move, origRookPiece, origKingPiece, newRookPiece, newKingPiece] #print("DEBUG: End of requestMoveCastling, our full moveList should be:\n%s\n" % moveList) return moveList
def GetNextStep(boardStateList): print("Current board:") DrawCurrentBoard(boardStateList) promptMessage = ("Would you like to add a new piece ('a'),\n\ remove an existing piece ('r'),\n\ or declare the board finished ('f'): ") legalNextMoves = ('a', 'r', 'f') nextStep = utilities.GetUserInput(promptMessage, legalNextMoves) return nextStep
def GetPlayerColor(): promptMessage = ("What color are you playing?") playerColor = utilities.GetUserInput(promptMessage, legalColors) # Check input legality # Set both the player and expected response colors if playerColor == "w": print("Playing as White\n") else: print("Playing as Black\n") return playerColor
def GetMoveType(): promptMessage = ("What sort of move do you want to make?\n\ Choose 'check','checkmate' or 'pawnpromotion' even if it includes a capture.") moveType = utilities.ChooseValueFromList(promptMessage, legalMoveTypes) # Append 'capture' to Moveype if it includes one if moveType == "check": promptMessage = ("Will this check move include a capture?") isCapture = utilities.GetUserInput(promptMessage, legalYN) if isCapture == 'y': moveType = "checkcapture" if moveType == "checkmate": promptMessage = ("Will this checkmate move include a capture?") isCapture = utilities.GetUserInput(promptMessage, legalYN) if isCapture == 'y': moveType = "checkmatecapture" if moveType == "pawnpromotion": promptMessage = ("Will this pawn promotion move include a capture?") isCapture = utilities.GetUserInput(promptMessage, legalYN) if isCapture == 'y': moveType = "pawnpromotioncapture" return moveType
def GetRequestBoard(): boardStateList = [] # send back as list, not string getBoard = False while getBoard == False: promptMessage = ( "Would you like to use or inspect starting boards in our Test_Board repository?" ) getRepoBoards = utilities.GetUserInput(promptMessage, legalYN) if getRepoBoards == 'y': boardFile = GetRequestBoardFromRepo() if boardFile != None: boardStateList = ReadBoardFile(boardFile, boardStateList) print("Here is the starting board you've chosen:") DrawCurrentBoard(boardStateList) promptMessage = ("Is this the board you want to use?") likeThisBoard = utilities.GetUserInput(promptMessage, legalYN) if likeThisBoard == 'y': getBoard = True break else: continue # Try again else: # User wants to build a new board boardStateList = BuildNewRequestBoard(boardStateList) getBoard = True break elif getRepoBoards == 'n': promptMessage = ("Would you like to create a new starting board?") getNewBoard = utilities.GetUserInput(promptMessage, legalYN) if getNewBoard == 'y': boardStateList = BuildNewRequestBoard(boardStateList) getBoard = True break else: print("Not sure what you want to do - Please try again.") continue # Try Again else: print("Not sure what you want to do... Exiting") sys.exit(1) return boardStateList
def BuildNewRequestBoard(boardStateList): # for fast board populating ask for this 4-character format, case-insensitive: # <color><piece><loc> print('''Building a new starting board.\n To make this fast, enter all the info about each new piece in one 4-character String. The format is case-insensitive: <color><piece><loc> . For example, adding a black Knight to square c6 would be: bnc6 ('n' for knight, since king gets 'k'). White ('w') pieces will be upper-cased for you. E.G. Adding a white rook to a1 (wra1) will put an "R" on square a1. At each prompt you will be shown the current board, and asked whether to add another piece('a'), remove a current piece('r'), or finish('f'). The new boardState will be added to the API request.\n ''') keepGoing = True while keepGoing == True: nextStep = GetNextStep(boardStateList) if nextStep == 'a': print("Adding a new piece to our board:") newPiece = GetBoardPiece(boardStateList) boardStateList.append(newPiece) elif nextStep == 'r': print("Request to remove a piece from our board - please choose:") pieceToRemove = GetBoardPiece(boardStateList) numPieces = utilities.CountItemsInList(boardStateList) if numPieces != 0 and numPieces != 1: # Remove the piece if we have 2 or more pieces on the board boardStateList.remove(pieceToRemove) else: print("Can't remove piece on board with %d pieces." % numPieces) continue elif nextStep == 'f': #Finish up print("Finished Board:") DrawCurrentBoard(boardStateList) keepGoing = False promptMessage = ( "Would you like to add this new board to the Test_Board repository?" ) saveBoard = utilities.GetUserInput(promptMessage, legalYN) if saveBoard == 'y': SaveBoardToRepo(boardStateList) else: print( "Not saving this board to the Test_Board repository. Continuing with building test case." ) print("Adding this board to the SFCS API request") return boardStateList else: print( "Process ERROR: Unexpected invalid input '%s' for GetNextStep. Exiting..." % nextStep) sys.exit(1)
def GetTestType(): promptMessage = ( "First Question - Is this a functional test or an expected error test?" ) testType = utilities.GetUserInput(promptMessage, legalTestTypes) # Check input legality if testType == 'e': print( "\nThis is an Expected Error Case expected to return an API Error message\n" ) if testType == 'f': print( "\nThis is a Functional Test Case expected to return a full API response.\n" ) return testType
def GetRequestBoardFromRepo(): choseBoard = False while choseBoard == False: repoBoardTypes = GetListRepoBoardTypes() promptMessage = ( "Here are the categories of starting boards in our Test_Board repository:" ) boardType = utilities.ChooseValueFromList(promptMessage, repoBoardTypes) boardNames = GetListBoardNames(boardType) numBoards = 0 numBoards = len(boardNames) if numBoards == 0: print("There are no boards in the %s TestBoards repository yet." % boardType) else: # Print out the list of boards, 1/line print( "Here is the current list of %d boards in the %s repository directory:" % (numBoards, boardType)) iter = 0 while iter <= (numBoards - 1): board = boardNames[iter] print(" %d: %s" % ((iter + 1), board)) # make choices 1-numItems, not (0-NumItems-1) iter += 1 promptMessage = ( "Do you want to use one of these boards ('u'), inspect another category ('a'), \n\ or build a new board ('b')?") legalChoice = ('u', 'a', 'b') useThisBoard = utilities.GetUserInput(promptMessage, legalChoice) if useThisBoard == 'u': boardName = utilities.ChooseValueFromList(promptMessage, boardNames) fullBoardName = os.path.join(fullTestBoardDir, boardType, boardName) choseBoard = True elif useThisBoard == 'a': continue # Try again elif useThisBoard == 'b': return # return None return fullBoardName
def CheckDestinationLegality(testType, destinationSquare): moveMessage = "" legalDest = False while legalDest == False: if len(destinationSquare) != 2: if testType == 'f': moveMessage += ( "ERROR: Invalid destination square value '%s'! columnrow format only." % destinationSquare) destinationSquare = input( "Please enter a move destination loc (<column><row>): ") continue # Try again else: # Expected Error - see if the user meant this as the error moveMessage += ( "WARNING: %s is an invalid location and will return a move error from the API" % destinationSquare) promptMessage = ( "Did you intend that to be the expected error?") intentional = utilities.GetUserInput(promptMessage, legalYN) if intentional == 'y': return moveMessage else: moveMessage += ( "ERROR: Invalid destination square value '%s'! columnrow format only." % destinationSquare) destinationSquare = input( "Please enter a move destination loc (<column><row>): " ) continue # Try again columnChar = destinationSquare[0] rowChar = destinationSquare[1] if columnChar not in (legalColumns): if testType == 'f': moveMessage += ("ERROR: Invalid column '%s'. Must be %s." % (columnChar, str(legalColumns))) destinationSquare = input( "Please enter a move destination loc (<column><row>): ") continue # Try again else: # Expected Error - see if the user meant this as the error moveMessage += ( "WARNING: %s is an invalid column and will return a board error from the API" % destinationSquare) promptMessage = ( "Did you intend that to be the expected error?") intentional = utilities.GetUserInput(promptMessage, legalYN) if intentional == 'y': return moveMessage else: moveMessage += ( "ERROR: Invalid destination square value '%s'! columnrow format only." % destinationSquare) destinationSquare = input( "Please enter a move destination loc (<column><row>): " ) continue # Try again if int(rowChar) not in (legalRows): if testType == 'f': moveMessage += ("ERROR: Invalid row '%s'. Must be %s." % (rowChar, str(legalRows))) destinationSquare = input( "Please enter a move destination loc (<column><row>): ") continue # Try again else: # Expected Error - see if the user meant this as the error moveMessage += ( "WARNING: %s is an invalid row and will return a board error from the API" % destinationSquare) promptMessage = ( "Did you intend that to be the expected error?") intentional = utilities.GetUserInput(promptMessage, legalYN) if intentional == 'y': return moveMessage else: moveMessage += ( "ERROR: Invalid destination square value '%s'! columnrow format only." % destinationSquare) destinationSquare = input( "Please enter a move destination loc (<column><row>): " ) continue # Try again legalDest = True return moveMessage