Esempio n. 1
0
        private static BoardState.Player NextPlayer(BoardState.Player player)
        {
            switch (player)
            {
            case BoardState.Player.Player1:
                return(BoardState.Player.Player2);

            case BoardState.Player.Player2:
                return(BoardState.Player.Player1);

            default:
                throw new ArgumentException("Invalid player");
            }
        }
Esempio n. 2
0
        public static GameState Tick(GameState gameState, PlayerInput playerInput)
        {
            if (playerInput.Player != gameState.NextPlayer)
            {
                throw new ArgumentException("Attempted to move out-of-turn");
            }
            BoardState newBoardState = BoardState.MakeMove(gameState.BoardState, playerInput.Player, playerInput.X, playerInput.Y);

            BoardState.Player newNextPlayer = NextPlayer(gameState.NextPlayer);
            BoardState.Winner newWinner     = BoardState.CheckForWinner(newBoardState);

            GameState newGameState = new GameState(newBoardState, newNextPlayer, newWinner);

            return(newGameState);
        }
Esempio n. 3
0
        private static float WinnerToReward(BoardState.Winner winner, BoardState.Player player)
        {
            switch (winner)
            {
            case BoardState.Winner.None:
                return(0.0f);

            case BoardState.Winner.Draw:
                return(0.5f);

            case BoardState.Winner.Player1:
                return((player == BoardState.Player.Player1) ? 1.0f : -1.0f);

            case BoardState.Winner.Player2:
                return((player == BoardState.Player.Player2) ? 1.0f : -1.0f);

            default:
                throw new NotImplementedException();
            }
        }
Esempio n. 4
0
        private static List <PlayerInput> FindAvailableActions(BoardState boardState, BoardState.Player player)
        {
            List <PlayerInput> availableActions = new List <PlayerInput>();

            for (int y = 0; y < boardState.Positions.GetLength(1); y++)
            {
                for (int x = 0; x < boardState.Positions.GetLength(0); x++)
                {
                    if (boardState.Positions[x, y] == BoardState.Player.None)
                    {
                        availableActions.Add(new PlayerInput(player, x, y));
                    }
                }
            }

            return(availableActions);
        }
Esempio n. 5
0
 public PlayerInput(BoardState.Player player, int x, int y)
 {
     Player = player;
     X      = x;
     Y      = y;
 }
Esempio n. 6
0
 public GameState(BoardState boardState, BoardState.Player nextPlayer, BoardState.Winner winner)
 {
     BoardState = boardState;
     NextPlayer = nextPlayer;
     Winner     = winner;
 }