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(); }
public HexAIMove GetMove(Game game) { var moves = HexAIMove.GenerateAllValidMoves(game).ToArray(); return(moves .OrderByDescending(move => Evaluate(move, game)) .First()); }
public Task <HexAIMove> GetMove(Game game) { var allmoves = HexAIMove.GenerateAllValidMoves(game).ToArray(); return(Task.FromResult(allmoves[random.Next(0, allmoves.Length)])); }
public Task <HexAIMove> GetMove(Game game) { var moves = HexAIMove.GenerateAllValidMoves(game).ToArray(); return(Task.FromResult(moves.OrderByDescending(move => Evaluate(move, game)).First())); }
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); }
public HexAIMove GetMove(Game game) { var allmoves = HexAIMove.GenerateAllValidMoves(game).ToArray(); return(allmoves[random.Next(0, allmoves.Length)]); }