예제 #1
0
        private static void PrintBoard(GameState gameState)
        {
            var playerBoardStrings = gameState.PlayerMoves.Select(m => Convert.ToString((long)m, 2).PadLeft(TotalBoardCells, '0')).ToArray();

            Console.WriteLine();

            for (int row = 0; row < TotalBoardCells - 1; row += BoardSize)
            {
                for (int col = 0; col < BoardSize; col += 1)
                {
                    var index = TotalBoardCells - (row + col) - 1;
                    Console.Write(playerBoardStrings[0][index] == '1' ? '0' : playerBoardStrings[1][index] == '1' ? '1' : '-');
                }

                Console.WriteLine();
            }

            Console.WriteLine();

            for (int i = 0; i < gameState.PlayerScores.Length; i += 1)
            {
                Console.WriteLine("{0}: {1}", Players[i].Name, gameState.PlayerScores[i]);
            }

            Console.WriteLine();
        }
예제 #2
0
 static void GameEnded(GameState gameState)
 {
     Console.WriteLine();
     var winner = gameState.Winner.HasValue ? Players[gameState.Winner.Value] : null;
     var message = winner == null ? "Tie game." : String.Format("The winner is {0}!", winner.Name);
     Console.WriteLine(message);
     PrintBoard(gameState);
 }
예제 #3
0
        public override Move MakeMove(GameState gameState)
        {
            Console.Write("{0}, it's your turn.  Please enter a move as row [space] col:  ", Name);

            Move move;
            while (!TryInputMove(out move))
            {
                Console.Write("Input needs to be row [space] col:  ");
            }

            return move;
        }
예제 #4
0
        public GameState ApplyMove(Move move)
        {
            var moveValue = move.InternalValue;
            var newMoves = (ulong[])PlayerMoves.Clone();
            newMoves[CurrentPlayer] |= moveValue;

            var newScores = (int[])PlayerScores.Clone();
            var scoreToAdd = GetTotalAddedScore(moveValue, newMoves[CurrentPlayer]);
            newScores[CurrentPlayer] += scoreToAdd;

            var newAvailableMoves = (ulong[])AvailableMoves.Clone();
            for (int i = MovesPlayed; i < newAvailableMoves.Length; i += 1)
            {
                if (newAvailableMoves[i] == moveValue)
                {
                    var temp = newAvailableMoves[MovesPlayed];
                    newAvailableMoves[MovesPlayed] = newAvailableMoves[i];
                    newAvailableMoves[i] = temp;
                    break;
                }
            }

            var result = new GameState
            {
                Winner = newScores[CurrentPlayer] > Game.WinningScore ? (int?)CurrentPlayer : null,
                MovesPlayed = MovesPlayed + 1,
                AvailableMoves = newAvailableMoves,
                CurrentPlayer = CurrentPlayer ^ 1,
                PlayerMoves = newMoves,
                PlayerScores = newScores,
            };

            return result;
        }
예제 #5
0
 public abstract Move MakeMove(GameState gameState);
예제 #6
0
 static void GameStateChanged(GameState gameState)
 {
     PrintBoard(gameState);
 }