Пример #1
0
 public string RegisterMove(Guid gameId, GameMove move)
 {
     GameFiguresList gameState;
     if(!games.TryGetValue(gameId, out gameState)) {
         throw new HttpResponseException(HttpStatusCode.NotFound);
     }
     gameState.ProcessMove(move);
     return gameState.GameState.GameStateNotation;
 }
Пример #2
0
 public DataService.RepositoryResult RegisterMove(Guid gameId, GameMove move)
 {
     GameState game;
     if(!games.TryGetValue(gameId, out game)) {
         return new RepositoryResult() { IsSuccessStatusCode = false, Exception = new ArgumentException() };
     }
     List<GameMove> moves = new List<GameMove>(game.Moves);
     moves.Add(move);
     game.Moves = moves;
     return new RepositoryResult() { IsSuccessStatusCode = true };
 }
Пример #3
0
        public void RegisterMove(GameMove move)
        {
            List<GameMove> currentMoves = new List<GameMove>(Moves);
            currentMoves.Add(move);
            Moves = currentMoves;

            //Figure[,] cells = ChessOperations.Parse(GameStateNotation);

            //ChessOperations.MakeMove(move.MoveNotation, cells);

            //ChessOperations.CreateStateByModel(cells);
        }
Пример #4
0
 public ActionResult CurrentMove(Guid gameId, int xfrom, int yfrom, int xto, int yto)
 {
     GameMove gameMove = new GameMove();
     gameMove.MoveNotation = ConvertToGameMove(xfrom, yfrom, xto, yto);
     RepositoryResult resultMoveRegister = repository.Games.RegisterMove(gameId, gameMove);
     if(!resultMoveRegister.IsSuccessStatusCode)
         throw new InvalidOperationException(resultMoveRegister.Exception.GetBaseException().Message);
     RepositoryResult<GameState> resultGameLoad = repository.Games.GetGame(gameId);
     GameModel gamemodel = new GameModel(resultGameLoad.Value);
     if(resultMoveRegister.IsSuccessStatusCode) {
         return View("Game", gamemodel);
     } else {
         throw new InvalidOperationException(resultMoveRegister.Exception.GetBaseException().Message);
     }
 }
Пример #5
0
        public void GameUpdate()
        {
            GameMove move = new GameMove() { MoveNotation = "a2 a4" };
            // Arrange
            GamesController controller = new GamesController(repository);

            // Act
            GameState updatedGame = controller.Get(gameId);
            List<GameMove> moves = new List<GameMove>(updatedGame.Moves);
            moves.Add(move);
            updatedGame.Moves = moves;
            controller.Put(updatedGame);
            updatedGame = controller.Get(gameId);

            // Assert
            GameState game = new GameState();
            game.RegisterMove(move);
            Assert.AreEqual(game.GameStateNotation, updatedGame.GameStateNotation);
        }
Пример #6
0
        public CurrentGameResult ProcessMove(GameMove move)
        {
            int[] coordinates = new int[4];
            coordinates = move.MoveParse();

            Figure figureFrom = GetFigureByCoordinate(coordinates[0], coordinates[1]);
            Figure figureTo = GetFigureByCoordinate(coordinates[2], coordinates[3]);
            if(figureFrom == null)
                throw new ArgumentException();
            if(figureTo != null && figureFrom.Color == figureTo.Color)
                return CurrentGameResult.YourFigureInCellTo;

            List<int[]> path = figureFrom.GeneratePath(coordinates[2], coordinates[3]);

            Figure figureForCheck = null;
            foreach(var cell in path) {
                foreach(var figureCheck in figures) {
                    if(figureCheck.IsIt(cell[0], cell[1])) {
                        figureForCheck = figureCheck;
                        break;
                    }
                }
                if(figureForCheck != null) return CurrentGameResult.BarrierInThePath;
            }

            figureTo.Coordinate=figureFrom.Coordinate;

            gameState.GameStateNotation = "xxxxxxxx/xxxxxxxx/xxxxxxxx/xxxxxxxx/xxxxxxxx/xxxxxxxx/xxxxxxxx/xxxxxxxx/ w KQkq - 0 1";
            for(int i = 0; i < 8; i++) {
                for(int j = 0; j < 8; j++) {
                    if(GetFigureByCoordinate(i, j) != null) {
                        gameState.GameStateNotation += GetFigureByCoordinate(i, j).Notation;
                    }
                }
            }
            gameState.GameStateNotation = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";

            List<Figure> figuresCopy;
            return CurrentGameResult.Ok;
        }