Пример #1
0
        public static Move GetNextMove(GameState gamestate, PlayerIdentityEnum identity)
        {
            var possibleMoves = GetPossibleMoves(gamestate).ToList();

            return(possibleMoves.Any()
                ? possibleMoves.OrderBy(_ => Guid.NewGuid()).First()
                : new Move.Pass(gamestate.MyHand.First().Type));
        }
Пример #2
0
    private static Piece createPiece(PlayerIdentityEnum owner, PieceTypeEnum type, int x, int y)
    {
        var piece = new Piece();

        piece.Owner           = owner;
        piece.Type            = type;
        piece.PositionOnBoard = new Position(x, y);
        return(piece);
    }
Пример #3
0
        private void ReadGameInfo()
        {
            var data = this.botInterface.ReadLine();

            var message = Deserialize <Message>(data);

            if (message.Type == MessageType.GameInfo)
            {
                var gameInfo = Deserialize <GameInfo>(message.JsonPayload);
                this.identity = gameInfo.Identity;
            }
            else
            {
                throw new Exception($"Expected to read GameInfo message, instead received: {message.Type} - Seed: {Seed}");
            }
        }
Пример #4
0
    private static int Evaluate(GameState gameState, PlayerIdentityEnum maximizingPlayer)
    {
        // TODO TODO consider postional stuff as well...
        // He considered some positional factors, subtracting ½ point for each doubled pawn, backward pawn, and isolated pawn.
        // Another positional factor in the evaluation function was mobility, adding 0.1 point for each legal move available.
        // Finally, he considered checkmate to be the capture of the king, and gave the king the artificial value of 200 points.

        var numMasters = gameState.Pieces.FindAll(p => p.Type == PieceTypeEnum.MasterPawn).Count;

        if (numMasters < 2)
        {
            foreach (Piece piece in gameState.Pieces)
            {
                if (piece.Type == PieceTypeEnum.MasterPawn)
                {
                    return(piece.Owner == maximizingPlayer ? int.MaxValue : int.MinValue);
                }
            }
        }

        int score = 0;

        foreach (Piece piece in gameState.Pieces)
        {
            if (IsMasterOnOpposingTempleSquare(piece))
            {
                return(piece.Owner == maximizingPlayer ? int.MaxValue : int.MinValue);
            }
            score += GetValue(piece, maximizingPlayer);
        }

        // TODO
        //score += GetPossibleMoves(gameState, gameState.MyHand, maximizingPlayer).Count();
        //score -= GetPossibleMoves(gameState, gameState.OpponentsHand, Opponent(maximizingPlayer)).Count();

        return(score);
    }
Пример #5
0
    private static GameState createGameState(PlayerIdentityEnum current, PlayerIdentityEnum mine, params Piece[] pieces)
    {
        var crane = new Card(CardType.Crane, new Position(0, 1));
        var crab  = new Card(CardType.Crab, new Position(0, 1));
        // Fifth card is placed in the correct direction for the currently playing player to take on hand.
        var dragon = new Card(CardType.Dragon, new Position(0, 1));

        var gameState = new GameState();

        gameState.CurrentlyPlaying = current;
        if (mine == Player1)
        {
            gameState.MyHand = new List <Card>()
            {
                crane
            };
            gameState.OpponentsHand = new List <Card>()
            {
                crab.flip()
            };
        }
        else
        {
            gameState.MyHand = new List <Card>()
            {
                crab.flip()
            };
            gameState.OpponentsHand = new List <Card>()
            {
                crane
            };
        }
        gameState.FifthCard = current == Player1 ? dragon : dragon.flip();
        gameState.Pieces    = new List <Piece>(pieces);
        return(gameState);
    }
Пример #6
0
 private static GameState createGameState(PlayerIdentityEnum current, params Piece[] pieces)
 {
     return(createGameState(current, Player1, pieces));
 }
Пример #7
0
 private static Piece master(PlayerIdentityEnum owner, int x, int y)
 {
     return(createPiece(owner, PieceTypeEnum.MasterPawn, x, y));
 }
Пример #8
0
    private static int GetValue(Piece p, PlayerIdentityEnum maximizingPlayer)
    {
        int value = p.Type == PieceTypeEnum.MasterPawn ? 100 : 10;

        return(p.Owner == maximizingPlayer ? value : -value);
    }
Пример #9
0
 private static PlayerIdentityEnum Opponent(PlayerIdentityEnum player)
 {
     return(player == PlayerIdentityEnum.Player1 ? PlayerIdentityEnum.Player2 : PlayerIdentityEnum.Player1);
 }
Пример #10
0
 private static Position TemplePosition(PlayerIdentityEnum player)
 {
     return(player == PlayerIdentityEnum.Player1 ? new Position(2, 0) : new Position(2, 4));
 }
Пример #11
0
 public Node(GameState gameState, PlayerIdentityEnum maximizingPlayer)
 {
     this.maximizingPlayer = maximizingPlayer;
     this.gameState        = gameState;
 }
Пример #12
0
    private static IEnumerable <Move.Play> GetPossibleMoves(GameState gameState, List <Card> playersHand, PlayerIdentityEnum player)
    {
        //return GetPossibleMoves2(playersHand, player).ToList().OrderByDescending(x => x. Item1).Select(x => x.Item2);
        //}
        // private IEnumerable<Tuple<int, Move.Play>> GetPossibleMoves2(List<Card> playersHand, PlayerIdentityEnum player) {
        foreach (var piece in gameState.Pieces.Where(p => p.Owner == player))
        {
            foreach (var card in playersHand)
            {
                foreach (var target in card.Targets)
                {
                    var newPosition   = piece.PositionOnBoard + target;
                    var potentialMove = new Move.Play(card.Type, piece.PositionOnBoard, newPosition);


                    if (IsPlayValid(gameState, potentialMove))
                    {
                        //var score = Evaluate(createGameStateWith(potentialMove), maximizingPlayer);
                        //yield return new Tuple<int, Move.Play>(score, potentialMove);
                        yield return(potentialMove);
                    }
                }
            }
        }
    }