Exemple #1
0
 public FastMove(HexAIMove move)
 {
     this.start     = FastIndex.FromByte(move.start.ToByte());
     this.target    = FastIndex.FromByte(move.target.ToByte());
     this.moveType  = move.moveType;
     this.promoteTo = move.promoteTo.ToFastPiece();
 }
Exemple #2
0
    public HexAIMove GetMove(Game game)
    {
        var moves = HexAIMove.GenerateAllValidMoves(game).ToArray();

        return(moves
               .OrderByDescending(move => Evaluate(move, game))
               .First());
    }
Exemple #3
0
    public Task <HexAIMove> GetMove(Game game)
    {
        var allmoves = HexAIMove.GenerateAllValidMoves(game).ToArray();

        return(Task.FromResult(allmoves[random.Next(0, allmoves.Length)]));
    }
Exemple #4
0
    public Task <HexAIMove> GetMove(Game game)
    {
        var moves = HexAIMove.GenerateAllValidMoves(game).ToArray();

        return(Task.FromResult(moves.OrderByDescending(move => Evaluate(move, game)).First()));
    }
Exemple #5
0
    private int Evaluate(HexAIMove move, Game game)
    {
        int  score   = random.Next(0, 25); // avoid making every run the same
        var  state   = game.GetCurrentBoardState();
        Team ourTeam = state.currentMove;
        Team enemy   = ourTeam.Enemy();

        (BoardState newState, List <Promotion> newPromotions) = move.Speculate(game);

        bool weAreChecking = MoveValidator.IsChecking(ourTeam, newState, newPromotions);
        bool enemyHasMoves = MoveValidator.HasAnyValidMoves(enemy, newPromotions, newState, state);

        if (weAreChecking && !enemyHasMoves)
        {
            return(int.MaxValue);
        }

        if (weAreChecking)
        {
            score += CheckBonus;
        }

        if (!enemyHasMoves)
        {
            score -= StalematePenalty;
        }

        if (move.moveType == MoveType.Attack)
        {
            var attacker = HexachessagonEngine.GetRealPiece(move.start, state, game.promotions);
            var victim   = HexachessagonEngine.GetRealPiece(move.target, state, game.promotions);
            score += AttackBonus;
            score += GetPieceValue(victim) - GetPieceValue(attacker);
        }
        else if (move.moveType == MoveType.EnPassant)
        {
            score += EnPassantBonus;
        }
        else if (move.moveType == MoveType.Move)
        {
            var mover = state.allPiecePositions[move.start];
            if (mover.piece.IsPawn())
            {
                int ranksForward = move.target.GetNumber() - move.start.GetNumber();
                if (ourTeam == Team.Black)
                {
                    ranksForward = -ranksForward;
                }

                ranksForward *= 5;

                score *= ranksForward;
            }
        }
        else
        {
            // Defend is pretty worthless for a bloodthirsty AI
            score -= 10;
        }

        return(score);
    }
Exemple #6
0
    public HexAIMove GetMove(Game game)
    {
        var allmoves = HexAIMove.GenerateAllValidMoves(game).ToArray();

        return(allmoves[random.Next(0, allmoves.Length)]);
    }