Exemple #1
0
 public static float Score(Board board, Piece.Colour player, AIConstants constants)
 {
     return(new BoardScorer(board, player, constants).Score());
 }
Exemple #2
0
 public AIPlayer(BoardNode board, Piece.Colour colour) : base(board, colour)
 {
     MoveChooser = new MoveChooser(colour);
     Constants   = AIConstants.Default;
 }
Exemple #3
0
 public BoardScorer(Board board, Piece.Colour player, AIConstants constants)
 {
     Board     = board;
     Player    = player;
     Constants = constants;
 }
Exemple #4
0
        /// <summary>
        /// Chooses the *best* move from a set of moves.
        /// </summary>
        /// <param name="board"></param>
        /// <param name="moves"></param>
        /// <returns></returns>
        public Move ChooseMove(Board board, HashSet <Move> moves)
        {
            if (moves.Count == 0)
            {
                Godot.GD.Print("oh no");
            }

            AIConstants constants = AIConstants.Default;

            float highestScore = float.NegativeInfinity;
            Move  bestMove     = moves.First();

            foreach (var move in moves)
            {
                var b = board.Clone();
                b.DoMove(move, _ => Piece.PieceType.Queen);

                float min = float.PositiveInfinity;

                var nextMoves = b.GetMoves(Player.Opposite());
                foreach (var nm in nextMoves)
                {
                    var b2 = b.Clone();
                    b2.DoMove(nm, _ => Piece.PieceType.Queen);

                    var score = BoardScorer.Score(b2, Player, constants);

                    if (score < min)
                    {
                        min = score;
                    }
                }

                // This stops the AI from oscilalting between positions
                if (History.Count > 2)
                {
                    if (move == History[History.Count - 2])
                    {
                        // Godot.GD.Print("repeat >:(");
                        min += constants.RepeatMoveScore;
                    }
                }

                if (min > highestScore)
                {
                    highestScore = min;
                    bestMove     = move;
                }

                // var score = BoardScorer.Score(b, Player, constants);

                // if (score > highestScore)
                // {
                //  highestScore = score;
                //  bestMove = move;
                // }
            }

            History.Add(bestMove);

            return(bestMove);
        }