Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Position GetBestMove(GameBoard Gb, Slot P, Difficulty Difficulty)
- {
- Position? bestSpace = null;
- List<Position> openSpaces = Gb.OpenSquares;
- GameBoard newBoard;
- for (int i = 0; i < openSpaces.Count; i++)
- {
- newBoard = Gb.Clone();
- Position newSpace = openSpaces[i];
- newBoard[newSpace.Row, newSpace.Col] = P;
- if (newBoard.Winner == Slot.Open && newBoard.OpenSquares.Count > 0)
- {
- Position tempMove = GetBestMove(newBoard, ((Slot)(-(int)P)), Difficulty);
- newSpace.Mark = tempMove.Mark;
- }
- else
- {
- if (newBoard.Winner == Slot.Open)
- newSpace.Mark = 0;
- else if (newBoard.Winner == Slot.X)
- newSpace.Mark = -1;
- else if (newBoard.Winner == Slot.O)
- newSpace.Mark = 1;
- }
- if (bestSpace == null ||
- (P == Slot.X && newSpace.Mark < ((Position)bestSpace).Mark) ||
- (P == Slot.O && newSpace.Mark > ((Position)bestSpace).Mark))
- {
- bestSpace = newSpace;
- }
- }
- return (Position)bestSpace;
- }
Add Comment
Please, Sign In to add comment