public bool makeMove(GameManager game) { int bestMove = -1; for (int numState = 0; numState < game.stateList.Count; numState++) { if (validMove(game, numState)) { if (numRowsToMove(game, numState) == 1) { if (isBestMove(game, numState, bestMove)) { bestMove = numState; } } } } if (bestMove != -1 && game.stateList.Count > 0) { int topDiff = game.rows[0] - game.stateList[bestMove].TopRow; int midDiff = game.rows[1] - game.stateList[bestMove].MidRow; int botDiff = game.rows[2] - game.stateList[bestMove].BotRow; if (topDiff != 0) { game.makeMove(0, topDiff); } else if (midDiff != 0) { game.makeMove(1, midDiff); } else if (botDiff != 0) { game.makeMove(2, botDiff); } } else { bool hasMoved = false; while (!hasMoved) { int randRow = rand.Next(3); int numToRemove = rand.Next(game.rows[randRow]+1); hasMoved = game.makeMove(randRow, numToRemove); } } return true; }
public bool makeMove(GameManager game) { bool moveMade = false; do { game.printBoard(); writer("Choose number of row"); int row = promptForInt("(0) for First Row, (1) for Second Row, (2) for Third Row"); int num = promptForInt("How many pieces do you want to take away?"); if (game.makeMove(row, num)) { moveMade = true; } else { writer("Invalid Input, try again"); } } while (!moveMade); return true; }