예제 #1
0
파일: AI.cs 프로젝트: jncronin/nmm
        public static int Heuristic(ulong board, List <ulong> possible_moves = null)
        {
            if (Board.CurrentPlayerHasLessThanThree(board))
            {
                return(-1000);       // this is a losing position
            }
            if (possible_moves == null)
            {
                possible_moves = Board.GetMoves(board);
            }

            if (possible_moves.Count == 0)
            {
                return(-1000);       // this is a losing position
            }
            /* We score +1 for a move, +2 if it forms a mill */
            int score    = 0;
            var old_runs = Board.GetRunPieces(board);

            foreach (var move in possible_moves)
            {
                var new_runs = Board.GetRunPieces(move);
                if (new_runs != old_runs && Board.CountBits(new_runs) >= Board.CountBits(old_runs))
                {
                    score += 5;
                }
                else
                {
                    score++;
                }
            }

            return(score);
        }
예제 #2
0
        public override ulong GetMove(ulong board)
        {
            ulong player_board, opp_board;
            int   player_piecestoplace, opp_piecestoplace;

            if (Board.IsWhiteTurn(board))
            {
                player_board         = Board.WhiteBoard(board);
                opp_board            = Board.BlackBoard(board);
                player_piecestoplace = Board.WhitePiecesLeftToPlace(board);
                opp_piecestoplace    = Board.BlackPiecesLeftToPlace(board);
            }
            else
            {
                player_board         = Board.BlackBoard(board);
                opp_board            = Board.WhiteBoard(board);
                player_piecestoplace = Board.BlackPiecesLeftToPlace(board);
                opp_piecestoplace    = Board.WhitePiecesLeftToPlace(board);
            }

            ulong new_player_board;

            if (Board.IsPlacementPhase(board))
            {
                var new_piece = InterpretInput("Place piece at: ");

                new_player_board = player_board | new_piece;
                player_piecestoplace--;
            }
            else
            {
                var old_piece = InterpretInput("Take piece from: ");
                var new_piece = InterpretInput("And place at: ");
                new_player_board = player_board & ~old_piece | new_piece;
            }
            throw new NotImplementedException();

            // see if we made a run
            var   old_runs      = Board.GetRunPieces(player_board);
            var   new_runs      = Board.GetRunPieces(new_player_board);
            ulong new_opp_board = opp_board;

            if (new_runs != old_runs && Board.CountBits(new_runs) >= Board.CountBits(old_runs))
            {
                var remove_piece = InterpretInput("Remove piece at: ");

                new_opp_board &= ~remove_piece;
            }

            return(Board.CreateBoardForNextTurn(IsWhite, new_player_board, new_opp_board, player_piecestoplace, opp_piecestoplace));
        }
예제 #3
0
파일: AI.cs 프로젝트: jncronin/nmm
        public static int Heuristic(ulong board, bool max_for_white, List <ulong> possible_moves = null)
        {
            if (!Board.IsPlacementPhase(board))
            {
                if (Board.IsWhiteTurn(board) && Board.WhitePiecesOnBoard(board) < 3)
                {
                    if (max_for_white)
                    {
                        return(-1000);
                    }
                    else
                    {
                        return(1000);
                    }
                }
                else if (!Board.IsWhiteTurn(board) && Board.BlackPiecesOnBoard(board) < 3)
                {
                    if (max_for_white)
                    {
                        return(1000);
                    }
                    else
                    {
                        return(-1000);
                    }
                }
            }

            if (possible_moves == null)
            {
                possible_moves = Board.GetMoves(board);
            }

            if (possible_moves.Count == 0)
            {
                if (Board.IsWhiteTurn(board))
                {
                    if (max_for_white)
                    {
                        return(-1000);
                    }
                    else
                    {
                        return(1000);
                    }
                }
                else
                {
                    if (max_for_white)
                    {
                        return(1000);
                    }
                    else
                    {
                        return(-1000);
                    }
                }
            }

            /* We score +1 for a move, +2 if it forms a mill */
            int score    = 0;
            var old_runs = Board.GetRunPieces(board);

            foreach (var move in possible_moves)
            {
                var new_runs = Board.GetRunPieces(move);
                if (new_runs != old_runs && Board.CountBits(new_runs) >= Board.CountBits(old_runs))
                {
                    score += 5;
                }
                else
                {
                    score++;
                }
            }

            if (Board.IsWhiteTurn(board))
            {
                if (max_for_white)
                {
                    return(score);
                }
                else
                {
                    return(-score);
                }
            }
            else
            {
                if (max_for_white)
                {
                    return(-score);
                }
                else
                {
                    return(score);
                }
            }
        }