示例#1
0
        public GoGame MakePlay(string initialState, bool blackPlaysNext, bool isNullGame, PositionPiece color, int row, int col, bool isValidPlay, string newState, out bool result)
        {
            GoGame game = null;

            if (!isNullGame)
            {
                game = new GoGame();
                game.BlackPlaysNext = blackPlaysNext;
                game.GameOver = false;
                game.GameState = initialState;
            }

            var activeGame = new Mock<IActiveGoGame>();
            activeGame.Setup(x => x.Game).Returns(game);
            activeGame.Setup(x => x.PlayerColor).Returns(color);

            var boardService = new Mock<IGoBoardData>();
            boardService.Setup(x => x.Play(color, row, col)).Returns(isValidPlay);
            boardService.Setup(x => x.GetBoardState(color)).Returns(newState);

            var goService = new GoService(activeGame.Object, null, boardService.Object, null);
            result = goService.Play(row, col);

            return game;
        }
示例#2
0
        public GoGame MakeNewGame(bool withActiveGame, bool withOpenGame, out GoGamePlayer player, out GoGame activeGame)
        {
            activeGame = null;
            player = new GoGamePlayer();
            player.Id = 5;

            var currentPlayer = new Mock<ICurrentPlayer>();
            currentPlayer.Setup(x => x.Player).Returns(player);

            var activeGoGame = new Mock<IActiveGoGame>();
            if (withActiveGame)
            {
                activeGame = new GoGame();
                activeGame.BlackPlayer = player;
                activeGame.BlackPlayerId = player.Id;
                activeGame.GameOver = false;
            }
            activeGoGame.Setup(x => x.Game).Returns(activeGame);

            var newGame = new GoGame();
            newGame.GameOver = false;
            newGame.GameState = "".PadLeft(19 * 19, '0');
            newGame.BlackPlaysNext = true;

            GoGame openGame = null;
            if (withOpenGame)
            {
                openGame = new GoGame();
                openGame.GameOver = false;
                openGame.GameState = "".PadLeft(19 * 19, '0');
                openGame.BlackPlaysNext = true;
                openGame.BlackPlayer = new GoGamePlayer();
                openGame.BlackPlayer.Id = 9;
                openGame.BlackPlayerId = openGame.BlackPlayer.Id;
            }

            var thePlayer = player;
            var dataService = new Mock<IDataService>();
            dataService.Setup(x => x.CreateNewGame()).Returns(newGame);
            dataService.Setup(x => x.FindGameWithNoOpponentPlayer(thePlayer)).Returns(openGame);

            var goService = new GoService(activeGoGame.Object, currentPlayer.Object, null, dataService.Object);
            return goService.NewGame();
        }