Beispiel #1
0
        public Move GetMove(Byte[] board, Player player)
        {
            _board = board;

            var savedPlayerColor = player.Color;

            var move = (mustJumpFromSquare == 0) ? DoAI(player) : GetJumpFromChoices(player);

            player.SetColor(savedPlayerColor);

            return move;
        }
Beispiel #2
0
        private Int32 alphabeta(List<Move> moves, Int32 plies, Player player, Int32 alpha, Int32 beta)
        {
            if (moves.Count == 0)
            {
                if (player.Color == Player.PlayerColor.WHITE)
                    return Int32.MaxValue;
                else
                    return Int32.MinValue;
            }

            if (plies == 0)
                return EvaluateBoard(null);

            Int32 best = Int32.MinValue;
            Int32 current;
            Int32 localAlpha = alpha;

            foreach (var m in moves)
            {
                _history.Push((Byte[])_board.Clone());

                MakeMove(m);

                player.SetColor((player.Color == Player.PlayerColor.RED) ? Player.PlayerColor.WHITE : Player.PlayerColor.RED);

                var nextMoves = GetPlayerLegalMoves(player);

                current = -(alphabeta(nextMoves, plies - 1, player, -beta, -localAlpha));

                player.SetColor((player.Color == Player.PlayerColor.RED) ? Player.PlayerColor.WHITE : Player.PlayerColor.RED);

                _board = _history.Pop();

                if (current > best)
                    best = current;

                if (best >= beta)
                    break;

                if (best > localAlpha)
                    localAlpha = best;
            }

            return best;
        }
Beispiel #3
0
        private Move DoAI(Player player, List<Move> movePool)
        {
            List<Move> potentialMoves = (movePool == null) ? GetPlayerLegalMoves(player) : movePool;

            // no moves, game's over
            if (potentialMoves.Count == 0)
                return null;

            // one move, must take it
            if (potentialMoves.Count == 1)
            {
                DoMustJumpLogic(potentialMoves[0]);
                return potentialMoves[0];
            }

            Move bestMove = potentialMoves[0];
            //_evaluated = 0; // Statistics only

            for (var i = 0; i < potentialMoves.Count(); i++)
            {
                _history.Push((Byte[])_board.Clone());

                MakeMove(potentialMoves[i]);

                player.SetColor((player.Color == Player.PlayerColor.RED) ? Player.PlayerColor.WHITE : Player.PlayerColor.RED);

                var moves = GetPlayerLegalMoves(player);

                //potentialMoves[i].SetScore(negamax(moves, 6, player));

                //potentialMoves[i].SetScore(minimax(moves, 6, player));

                potentialMoves[i].SetScore(alphabeta(moves, 6, player, Int32.MinValue, Int32.MaxValue));

                player.SetColor((player.Color == Player.PlayerColor.RED) ? Player.PlayerColor.WHITE : Player.PlayerColor.RED);

                if (potentialMoves[i].Score > bestMove.Score)
                    bestMove = potentialMoves[i];

                _board = (Byte[])_history.Pop();
            }

            if (bestMove != null)
                DoMustJumpLogic(bestMove);

            score = bestMove.Score;

            return bestMove;
        }
Beispiel #4
0
 private static void ChangeSides(Player player)
 {
     player.SetColor((player.Color == Player.PlayerColor.RED) ? Player.PlayerColor.WHITE : Player.PlayerColor.RED);
 }