Example #1
0
        public static Game CreateGame()
        {
        var game = new Game
                           {
                               Id = Guid.NewGuid().GetHashCode(),
                               WhitePlayerIdentifier = Guid.NewGuid().GetHashCode(),
                               BlackPlayerIdentifier = Guid.NewGuid().GetHashCode(),
                               Moves = new List<string>(),
                               Pieces = new Dictionary<string, string>
                                            {
{"a1", "wr" }, {"b1" ,"wn" }, {"c1", "wb" }, {"d1" ,"wq" }, {"e1", "wk" }, {"f1" ,"wb" }, {"g1", "wn" }, {"h1" ,"wr" },
{"a2", "wp" }, {"b2" ,"wp" }, {"c2", "wp" }, {"d2" ,"wp" }, {"e2", "wp" }, {"f2" ,"wp" }, {"g2", "wp" }, {"h2" ,"wp" },

{"a8", "br" }, {"b8" ,"bn" }, {"c8", "bb" }, {"d8" ,"bq" }, {"e8", "bk" }, {"f8" ,"bb" }, {"g8", "bn" }, {"h8" ,"br" },
{"a7", "bp" }, {"b7" ,"bp" }, {"c7", "bp" }, {"d7" ,"bp" }, {"e7", "bp" }, {"f7" ,"bp" }, {"g7", "bp" }, {"h7" ,"bp" }
                                            }
                           };

            if (Games.ContainsKey(game.Id))
            {
                throw new Exception("Game already exists.");
            }

            Games.Add(game.Id, game);
            return game;
        }
Example #2
0
        public MoveValidator(Game game, string turn = null)
        {
            Pieces = game.Pieces;
            if (turn == null)
            {
                Turn = game.Moves.Count()%2 == 0 ? "w" : "b";
            }
            else
            {
                Turn = turn;
            }
            Moves = game.Moves;

            Board = TransformToArray(Pieces);


        }