public Move(int moveID, int[,] board, bool maxMove, int startValue) { this.moveID = moveID; playMove(board, moveID, maxMove); int tempScore = Connect4BoardEvaluation.evaluateMoveBoard(postBoard, moveID, moveYID, maxMove); boardValue = maxMove ? startValue + tempScore : startValue - tempScore; }
public static int findBestMove(int[,] board, int depth) { int startValue = Connect4BoardEvaluation.evaluateStartPosition(board); int bestMoveId = getPossibleMoves(board)[0]; int bestValue = -10000; int bestDepth = 0; maxDepth = depth; List <int[]> values = new List <int[]> (); foreach (int i in getPossibleMoves(board)) { Move tempMove = new Move(i, board, true, startValue); int[] value = alphaBeta(tempMove, maxDepth - 1, -10000, 10000, false); values.Add(new int[] { value[0], tempMove.moveID, value[1] }); if (value[0] > bestValue) { bestValue = value[0]; bestMoveId = tempMove.moveID; bestDepth = value[1]; } if (value[0] == bestValue && value[1] < bestDepth && value[0] < 0) { bestValue = value[0]; bestMoveId = tempMove.moveID; bestDepth = value[1]; } if (value[0] == bestValue && value[1] > bestDepth && value[0] > 0) { bestValue = value[0]; bestMoveId = tempMove.moveID; bestDepth = value[1]; } } return(bestMoveId); }