Exemplo n.º 1
0
Arquivo: AI.cs Projeto: 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);
                }
            }
        }