public GamePage(int size = 5) { this.size = size - 1; Game = new GoGame(size + 2); Buttons = new Button[(size + 2), (size + 2)]; InitializeComponent(); }
public async Task <GoResponse> CreateGameAsync(GoGame state) { try { Debug.Assert(state != null && state.Id != Guid.Empty, "state != null && state.Id != Guid.Empty"); await LoadState(); state.Created = DateTime.UtcNow; if (!_states.ContainsKey(state.Id)) { _states.Add(state.Id, state); } await _repository.AddGameAsync(state); // The following method sets _state and coerses the FuegoInstance // to match that state through a series of GTP commands. await EnsureFuegoStartedAndMatchingGame(state.Id); return(new GoResponse(GoResultCode.Success)); } catch (GoEngineException gex) { return(new GoGameStateResponse(gex.Code, null)); } catch (Exception) { return(new GoGameStateResponse(GoResultCode.InternalError, null)); } }
public BruGoView(Size size, GoGame game, GameRenderer renderer) : base(size, game, renderer) { cache = new BruGoCache(); AllowCursor = true; AllowNavigation = false; statusLabel = new Label() { Dock = DockStyle.Bottom, }; using (var graphics = CreateGraphics()) { var textSize = graphics.MeasureString("Text", statusLabel.Font); statusLabel.Height = (int)textSize.Height; } Controls = new List <Control>() { statusLabel }; OnResize(); requestTimer = new Timer() { Interval = 15000 }; requestTimer.Tick += Timeout; ToStart(); }
public GameBrowseView(Size size, GoGame game, GameRenderer renderer) : base(size, game, renderer) { CreateCommentBox(); AllowCursor = false; }
public static void SaveGame(GoGame game, string path) { var writer = new StreamWriter(File.OpenWrite(path)); SaveGame(game, writer); writer.Close(); }
public Form1() { InitializeComponent(); game = new GoGame("player1", "player2"); PicShow = new PictureBox(); this.Width = game.board.GetCellSize() * (game.board.GetBoardSize() + 4); this.Height = game.board.GetCellSize() * (game.board.GetBoardSize() + 2); }
private static void RenderShadow(this GoGame goGame, GameRenderer renderer, GoNode node) { if ((node != goGame.currentNode) && (node is GoMoveNode)) { var nodeStone = (node as GoMoveNode).Stone; renderer.DrawShadow(nodeStone.X, nodeStone.Y, nodeStone.IsBlack); } }
public override void Edit(GoGame game, byte x, byte y) { ClearMarkup(game, x, y); var node = game.CurrentNode; node.EnsureMarkup(); node.Markup.Marks.Add(new Mark(x, y, markType)); }
public Controller(GoGame goGame, UserSettings userSettings, CaseDico caseDico) { mainForm = goGame; this.userSettings = userSettings; caseDictionnary = caseDico; calculator = new Calculator(); playingNow = true; goban = new Goban(userSettings); gobanCalculator = new GobanCalculator(this); }
public static void SaveGame(GoGame game, TextWriter writer) { var node = game.RootNode; writer.Write("(;GM[1]FF[4]SZ[" + game.BoardSize + "]PW[" + game.Info.WhitePlayer + "]PB[" + game.Info.BlackPlayer + "]"); SaveNode(writer, node); writer.Write(")"); }
public static void Render(this GoGame goGame, GameRenderer renderer) { renderer.ClearBoard(goGame.board.Size); for (byte x = 0; x < goGame.board.Size; x++) { for (byte y = 0; y < goGame.board.Size; y++) { if (goGame.board.Black[x, y]) { renderer.DrawStone(x, y, true); } else if (goGame.board.White[x, y]) { renderer.DrawStone(x, y, false); } } } if (goGame.currentNode is GoMoveNode) { var stone = (goGame.currentNode as GoMoveNode).Stone; renderer.DrawMoveMark(stone.X, stone.Y, goGame.board.HasStone(stone.X, stone.Y, false)); if (goGame.showVariants == Variants.Siblings) { goGame.currentNode.ParentNode.ChildNodes. ForEach(n => RenderShadow(renderer, n)); } } if (goGame.showVariants == Variants.Children) { goGame.currentNode.ChildNodes. ForEach(n => RenderShadow(renderer, n)); } if (goGame.currentNode.Markup != null) { RenderMarkup(renderer, goGame.currentNode.Markup); } if (goGame.currentNode is GoMoveNode) { var stone = (goGame.currentNode as GoMoveNode).Stone; if (stone.X > 19) { renderer.DrawMessage((stone.IsBlack ? "Black" : "White") + " passes"); } } }
public void A2_MoveUser_Test() { HTMLRenderer r = new HTMLRenderer(); GoGame g = new GoGame(r); g.Init(5, 5); Assert.AreEqual(0, g.User.X); g.MoveUser("RIGHT"); Assert.AreEqual(1, g.User.X); }
private void button2_Click(object sender, EventArgs e) { game.stop = false; if (gametype == 0) { game = new ChessGame("player1", "player2"); } else { game = new GoGame("player1", "player2"); } this.Refresh(); }
private static IEnumerable <GoStat> RunAnalysis(GoGame game) { game.ToStart(); var analyser = new Analyser(); do { analyser.AnalyseStep(game.board); }while (game.ToNextMove()); return(analyser.Statistic); }
public override void Edit(GoGame game, byte x, byte y) { var input = new StringInput(); var dialog = new ValueDialog <StringInput>("Label: ", input); if (dialog.ShowDialog() == DialogResult.OK && input.Text != string.Empty) { ClearMarkup(game, x, y); var node = game.CurrentNode; node.EnsureMarkup(); node.Markup.Labels.Add(new TextLabel(x, y, input.Text)); } }
public override void Edit(GoGame game, byte x, byte y) { var stone = new Stone(x, y, true); stone.IsBlack = game.BlackToPlay(); if (game.CanPlace(stone)) { if (!game.Continue(stone)) { game.PlaceStone(stone); } SoundUtils.Play("Stone"); } }
public void Allow_BreathPreventsSuicide() { const short n = 3; GoGame game = new GoGame { BoardSize = n }; game.ProposedPlay(new Loc(0, 0)); // X game.ProposedPlay(new Loc(0, 1)); // O game.ProposedPlay(new Loc(2, 0)); // X game.ProposedPlay(new Loc(2, 1)); // O game.ProposedPlay(new Loc(1, 0)); // 1 Assert.True(game.blackChains.Count == 1); Assert.True(game.blackChains.First().Liberties.Count == 1); Assert.True(game.blackChains.First().Liberties.First().Equals(new Loc(1, 1))); }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex == 0) { gametype = 0; game = new ChessGame("player1", "player2"); this.Refresh(); } else { gametype = 1; game = new GoGame("player1", "player2"); this.Refresh(); } }
static void Main(string[] args) { // мы тут тестируем наш рендерер - он рендерит не в HTML а в консоль, тоесть там просто нет <br /> ConsoleRenderer r = new ConsoleRenderer(); GoGame g = new GoGame(r); g.Init(5, 5); g.MoveUser(GoGame.D_RIGHT); g.MoveUser(GoGame.D_DOWN); String temp = g.RenderField(); Console.WriteLine(temp); }
public void BuidInfoGame(GoGame game) { b.Root() .p("GM", "1") .p("FF", "4") .p("CA", "UTF-8") .p("SZ", game.BoardSize) .p("KM", game.Info.Komi) .p("PW", game.Info.WhitePlayer) .p("PB", game.Info.BlackPlayer); if (game.Info.Handicap > 1) { b.p("HA", game.Info.Handicap); } }
protected void ClearMarkup(GoGame game, byte x, byte y) { if (game.CurrentNode.Markup != null) { game.CurrentNode.Markup.Marks.RemoveAll( delegate(Mark mark) { return(mark.X == x && mark.Y == y); }); game.CurrentNode.Markup.Labels.RemoveAll( delegate(TextLabel label) { return(label.X == x && label.Y == y); }); } }
public void A1_Dimensions_Test() { HTMLRenderer r = new HTMLRenderer(); GoGame g = new GoGame(r); g.Init(5, 5); Assert.AreEqual(5, g.DimX); Assert.AreEqual(5, g.DimY); g = new GoGame(r); g.Init(10, 5); Assert.AreEqual(10, g.DimX); Assert.AreEqual(5, g.DimY); }
public void HubContextService_ChangeUsernameWithActiveGameAndToAlternatePlayerWithActiveGame() { var session = new Session(); session.User = new User(); session.User.Username = "******"; var requestSession = new Mock<ICurrentRequestSession>(); requestSession.Setup(x => x.Session).Returns((Session)session); var mockHubContext = new MockHubContext("connection #5"); IActiveGoGame activeGame; CreateActiveGame(session.User, null, "adbbdfd999bd4541ba4d742a858dc5f1", out activeGame); var game = new GoGame(); User newUser = new User(); newUser.Username = "******"; newUser.Id = 8; GoGamePlayer newPlayer = new GoGamePlayer(); newPlayer.User = newUser; newPlayer.UserId = 8; newPlayer.Id = 14; var newGame = new GoGame(); newGame.BlackPlayer = newPlayer; newGame.WhitePlayer = null; newGame.GameState = "0123400003430400"; newGame.HubId = "5ad61645b24f4f40b55309c96c1a9b81"; newGame.Id = 23; var dataService = new Mock<IDataService>(); dataService.Setup(x => x.FindOrCreateUser(It.Is<string>(y => y.Equals("new user")))).Returns(newUser); dataService.Setup(x => x.FindGoPlayer(It.Is<int>(y => y == 8))).Returns(newPlayer); dataService.Setup(x => x.FindActiveGoGame(It.Is<int>(y => y == 14))).Returns(newGame); mockHubContext.Client<IHubClient>("5ad61645b24f4f40b55309c96c1a9b81").Setup(x => x.updateGame(It.Is<object>(y => true))).Verifiable(); mockHubContext.Groups.Setup(x => x.Remove(It.Is<string>(y => y.Equals("connection #5")), It.Is<string>(y => y.Equals("adbbdfd999bd4541ba4d742a858dc5f1")))).Verifiable(); mockHubContext.Groups.Setup(x => x.Add(It.Is<string>(y => y.Equals("connection #5")), It.Is<string>(y => y.Equals("5ad61645b24f4f40b55309c96c1a9b81")))).Verifiable(); mockHubContext.Client<IHubClient>("connection #5").Setup(x => x.setUsername(It.Is<string>(y => y.Equals("new user")))).Verifiable(); var hubGoService = new GameOfGoHubService(mockHubContext.Object, requestSession.Object, activeGame, null, dataService.Object); hubGoService.ChangeUser("new user"); mockHubContext.VerifyClients(); mockHubContext.Groups.VerifyAll(); }
public GameView(Size size, GoGame game, GameRenderer renderer) : base(size) { if ((game == null) || (renderer == null)) { throw new ArgumentException("GoGame and Renderer arguments cannot be null"); } Game = game; Renderer = renderer; Cursor = new Point(Game.BoardSize / 2, Game.BoardSize / 2); AllowCursor = true; AllowNavigation = true; OnResize(); EnableButtons(); }
public GnuGoView(Size size, GoGame game, GameRenderer renderer, GTP gtp, GnuGoColor gnugoColor, GTPReset reset) : base(size, game, renderer) { this.gtp = gtp; this.reset = reset; this.gnugoColor = gnugoColor; blackToPlay = true; AllowCursor = true; AllowNavigation = false; timer = new Timer() { Interval = 50, }; timer.Tick += (s, e) => this.gtp.Update(); Close += (s, e) => CloseGTP(); statusLabel = new Label() { Dock = DockStyle.Bottom, }; using (var graphics = CreateGraphics()) { var textSize = graphics.MeasureString("Text", statusLabel.Font); statusLabel.Height = (int)textSize.Height; } OnResize(); Controls = new List <Control>() { statusLabel }; Init(); }
private void button2_Click(object sender, EventArgs e) { //construct a tw array // 00 01 02 03 // 10 11 12 13 // 20 21 22 23 // 30 31 32 33 // 40 41 42 43 //Imagine black is in 12, 21 23 and 32 position //White cannot be place in 22 bcoz the neightbors belong to black/enemy and it will not have any libery //for simplicity //int[,] matrix = new int[,] { {0,0,0,0}, // {0,0,2,0}, // {0,2,0,2}, // {0,0,2,0}, // {0,0,0,0}}; ////we are trying to place white in the middle of 2 that is in the position 22 //bool[,] blackstones = new bool[matrix.GetLength(0), matrix.GetLength(1)]; ////set black stones //blackstones[1, 2] = true; //blackstones[2, 3] = true; //blackstones[2, 1] = true; //blackstones[3, 2] = true; ////set white stones //bool[,] whitestones = new bool[matrix.GetLength(0), matrix.GetLength(1)]; ////set ////blackstones[1, 2] = true; ////blackstones[2, 3] = true; ////blackstones[2, 1] = true; ////blackstones[3, 2] = true; //////set white stones ////point is 2,2 //bool result = IsLegalMove(false, 2, 2, blackstones, whitestones); GoGame obj = new GoGame(4, 5); }
public GoGameForm() { InitializeComponent(); var random = new Random(0); FieldCoordinates optimizedPlayoutGenerator(GameState gameState) { var allowedActions = gameState.GetAllowedActionsForRandomPlayout(); return(allowedActions.Any() ? random.Next(allowedActions) : FieldCoordinates.Pass); } var game = new GoGame(); var gameRootState = new GameState(9); var playoutRootNode = new GamePlayoutNode <GameState, FieldCoordinates>(gameRootState); var playoutTree = new GamePlayoutTree <GameState, FieldCoordinates, Stone>(playoutRootNode); var playoutGenerator = new GamePlayoutRandomGenerator <GameState, Stone, FieldCoordinates>(game, optimizedPlayoutGenerator); //var mctsSettings = new GoMctsSettings(random) { PlayoutGenerator = playoutGenerator }; var mctsExpander = new MCTreeSearchExpander <GoGame, GameState, FieldCoordinates, Stone>(game, random); var mcts = new GoMcts(mctsExpander, playoutGenerator); var mctsRootNode = new GoMctsNode(null, gameRootState, null); var mctsNavigator = new GoMctsNavigator(mcts, game, mctsRootNode); MainNavigator1 = new ObservableGameTreeNavigator <GoMctsNavigator, GameState, FieldCoordinates, Stone, MCTreeSearchNode <GameState, FieldCoordinates> >(mctsNavigator); //new MCTreeSearchNavigator<GoMcts, GoGame, GoMctsNode, GameState, FieldCoordinates, Stone>(mcts, game, mctsRootNode); //MainNavigator1 = new MCTreeNavigator<GoGame, GameState, FieldCoordinates, Stone>(mcts); var playoutNavigator = new GamePlayoutNavigator <GameState, FieldCoordinates, Stone>(playoutTree); PlayoutNavigator = new ObservableGameTreeNavigator <GamePlayoutNavigator <GameState, FieldCoordinates, Stone>, GameState, FieldCoordinates, Stone, GamePlayoutNode <GameState, FieldCoordinates> >(playoutNavigator); new GameTreeNavigationController <GoGame, GameState, FieldCoordinates, Stone, MCTreeSearchNode <GameState, FieldCoordinates> >(MainNavigator1, mainBoardNavigationScroll); new GameTreeNavigationController <GoGame, GameState, FieldCoordinates, Stone, GamePlayoutNode <GameState, FieldCoordinates> >(PlayoutNavigator, playoutScrollBar); goBoardControl1.OnAction += MainBoardControl_OnAction; InitializePreparedPositionControl(); MainNavigator1.Forwarded += MainNavigator_Forwarded; MainNavigator1.Navigated += MainNavigator_Navigated; PlayoutNavigator.Forwarded += PlayoutNavigator_Forwarded; PlayoutNavigator.Navigated += PlayoutNavigator_Navigated; }
public void InitializeUC(GoGame game) { PrepareUI(); _Game = game; if (game.IsGamePlayed) { grpResult.Enabled = false; cmbResult.SelectedIndex = (int)game.Result; } _EGDPlayer1 = DBHelper.GetPlayerByIDUsingHttpClient(game.Player1.EGDPinCode).Result; _EGDPlayer2 = DBHelper.GetPlayerByIDUsingHttpClient(game.Player2.EGDPinCode).Result; ucPlayerInfo1.InitializeUC(game.Player1, _EGDPlayer1); ucPlayerInfo2.InitializeUC(game.Player2, _EGDPlayer2); lblGameName.Text = game.GameLabel; txtTableName.Text = game.GameLabel; txtHandicap.Text = ""; SubscribeToEvents(); }
public void Allow_Kill() { const short n = 4; GoGame game = new GoGame { BoardSize = n }; game.ProposedPlay(new Loc(1, 0)); // X game.ProposedPlay(new Loc(0, 2)); // O game.ProposedPlay(new Loc(1, 1)); // X game.ProposedPlay(new Loc(1, 2)); // O game.ProposedPlay(new Loc(n, n)); // X: PASS game.ProposedPlay(new Loc(2, 1)); // O game.ProposedPlay(new Loc(n, n)); // X: PASS game.ProposedPlay(new Loc(2, 0)); // O game.ProposedPlay(new Loc(n, n)); // X: PASS game.ProposedPlay(new Loc(0, 0)); // O game.ProposedPlay(new Loc(0, 1)); // 1 Assert.True(game.blackChains.Count == 1); Assert.True(game.whiteChains.Count == 2); Assert.True(game.PrisonersTakenByBlack == 1); Assert.True(game.blackChains.First().Liberties.Count == 1); Assert.True(game.blackChains.First().Liberties[0].Equals(new Loc(0, 0))); }
public async Task UpdateGameAsync(GoGame game) { try { using (var db = new GameContext()) { db.GoGame.Update(game); await db.SaveChangesAsync(); } } catch (JsonException jex) { //throw; } catch (SqliteException slex) { //throw; } catch (Exception ex) { //throw; } }
public void ClearBoard(int handicap, int minutes, bool isTwoHumanPlayers, int boardSize) { // set the game settings m_gameInfo = new GoGameInfo(); m_gameInfo.Size = boardSize; m_gameInfo.Komi = 0.0f; m_gameInfo.Handicap = handicap; m_gameInfo.TimeSettings.MainTime = new TimeSpan(0, minutes, 0); m_gameInfo.TimeSettings.Byoyomi = new TimeSpan(0, 0, 5); m_gameInfo.TimeSettings.NumberOfMovesPerByoyomi = 1; m_game = new GoGame(m_gameInfo); m_game.GameIsOver += m_game_GameIsOver; StartPachi(); if (m_gtpEngine != null) { if (!isTwoHumanPlayers) { m_gtpEngine.SetGameInfo(m_gameInfo); } } }
private static List <GoGame> GetGoGames(AGoCompetition goCompetition, string groupName, string Path) { List <GoGame> Games = new List <GoGame>(); using (StreamReader sr = new StreamReader(Path)) { var line = ""; int stage = 1; while (true) { line = sr.ReadLine(); if (line != null) { var split = line.Split(','); if (split.Count() == 1) { stage = Convert.ToInt32(split[0].Replace("Maç ", string.Empty)); } else if (split.Count() == 2) { Player player1 = GetGoPlayerByName(goCompetition.Players, split[0]); Player player2 = GetGoPlayerByName(goCompetition.Players, split[1]); GoGame game = new GoGame(goCompetition, groupName, stage, player1, player2); Games.Add(game); } } else { break; } } } return(Games); }
public void Allow_MergeMakesBreath() { const short n = 4; GoGame game = new GoGame { BoardSize = n }; game.ProposedPlay(new Loc(0, 0)); // X game.ProposedPlay(new Loc(1, 1)); // O game.ProposedPlay(new Loc(2, 0)); // X game.ProposedPlay(new Loc(2, 1)); // O game.ProposedPlay(new Loc(n, n)); // X: PASS game.ProposedPlay(new Loc(0, 1)); // O game.ProposedPlay(new Loc(1, 0)); // 1 Assert.True(game.blackChains.Count == 1); Assert.True(game.whiteChains.Count == 1); Assert.True(game.blackChains.First().Liberties.Count == 1); Assert.True(game.blackChains.First().Liberties[0].Equals(new Loc(3, 0))); }
private void UpdateGame(GoGame game) { if (game != null) { HubContext.Clients[game.HubId].updateGame(new { GameState = game.GameState, BlackPlaysNext = game.BlackPlaysNext, BlackPlayer = game.BlackPlayer == null ? "none" : game.BlackPlayer.User.Username, WhitePlayer = game.WhitePlayer == null ? "none" : game.WhitePlayer.User.Username, GameOver = game.GameOver, }); } else { HubContext.Clients[HubContext.Context.ConnectionId].updateGame(new { GameState = "".PadLeft(19 * 19, '0'), BlackPlaysNext = true, BlackPlayer = "none", WhitePlayer = "none", GameOver = true }); } }
private GoGame CreateActiveGame(User whitePlayer, User blackPlayer, string hubId, out IActiveGoGame activeGame) { var game = new GoGame(); game.BlackPlayer = new GoGamePlayer(); game.WhitePlayer = new GoGamePlayer(); if (whitePlayer != null) { game.WhitePlayer.User = whitePlayer; } else { game.WhitePlayer.User = new User(); game.WhitePlayer.User.Username = "******"; } if (blackPlayer != null) { game.BlackPlayer.User = blackPlayer; } else { game.BlackPlayer.User = new User(); game.BlackPlayer.User.Username = "******"; } game.GameState = "012340123401234"; game.HubId = hubId; game.Id = 17; var mockActiveGame = new Mock<IActiveGoGame>(); mockActiveGame.Setup(x => x.Game).Returns((GoGame)game); activeGame = mockActiveGame.Object; return game; }
public void Ko() { const short n = 4; GoGame game = new GoGame { BoardSize = n }; /* First Step */ game.ProposedPlay(new Loc(0, 1)); // X game.ProposedPlay(new Loc(0, 0)); // O game.ProposedPlay(new Loc(n, n)); // X: PASS game.ProposedPlay(new Loc(1, 1)); // O game.ProposedPlay(new Loc(n, n)); // X: PASS game.ProposedPlay(new Loc(2, 0)); // O RequestResponse response = game.ProposedPlay(new Loc(1, 0)); // X: 1 Assert.True(response.Move.ChainsKilled.Count == 1); // only one group Assert.True(response.Move.ChainsKilled[0].Stones.Count == 1); // of only one stone is killed Assert.True(game.PossibleKoLoc.Equals(new Loc(0, 0))); /* Second Step */ response = game.ProposedPlay(new Loc(0, 0)); // O: 2 Assert.True(game.blackChains.Count == 2); Assert.True(game.whiteChains.Count == 2); Assert.True(response.Reason == ReasonEnum.Ko); /* Play Elsewhere */ response = game.ProposedPlay(new Loc(2, 2)); // O: 2, again. Assert.True(response.Reason == ReasonEnum.Fine); Assert.True(response.Move.StonePlaced.IsWhite); }
private void LeaveGame(GoGame game) { HubContext.Groups.Remove(HubContext.Context.ConnectionId, game.HubId); }
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(); }
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; }
public void LiveOtherCorner() { const short n = 2; GoGame game = new GoGame { BoardSize = n }; game.ProposedPlay(new Loc(1, 1)); Assert.True(game.blackChains.Count == 1); Assert.True(game.blackChains[0].Stones.Count == 1); Assert.True(game.blackChains[0].Liberties.Count == 2); Assert.True(game.blackChains[0].Liberties.Contains(new Loc(1, 0))); Assert.True(game.blackChains[0].Liberties.Contains(new Loc(0, 1))); }
public void MakesGroups() { const short n = 4; GoGame game = new GoGame { BoardSize = n }; game.ProposedPlay(new Loc(0, 0)); // X game.ProposedPlay(new Loc(1, 0)); // O game.ProposedPlay(new Loc(0, 1)); // X game.ProposedPlay(new Loc(1, 1)); // O game.ProposedPlay(new Loc(1, 2)); // X game.ProposedPlay(new Loc(2, 2)); // O // TEST: explicitly check number of groups and each groups stones and breaths. Assert.True(game.blackChains.Count == 2); Assert.True(game.blackChains.Where(chain => chain.Stones.Count == 1).First().Liberties.Count == 2); // the one with 1 stone has 2 libs Assert.True(game.blackChains.Where(chain => chain.Stones.Count == 2).First().Liberties.Count == 1); // the one with 2 stones has 1 lib Assert.True(game.whiteChains.Count == 2); Assert.True(game.whiteChains.Where(chain => chain.Stones.Count == 1).First().Liberties.Count == 3); // the one with 1 stone has 3 libs Assert.True(game.whiteChains.Where(chain => chain.Stones.Count == 2).First().Liberties.Count == 2); // the one with 2 stones has 2 libs }
public void PassPass_EndGame() { const short n = 2; GoGame game = new GoGame { BoardSize = n }; game.ProposedPlay(new Loc(n, n)); game.ProposedPlay(new Loc(n, n)); Assert.True(game.IsOver); }
public void HubContextService_TestNewGame() { var session = new Session(); session.User = new User(); session.User.Username = "******"; var requestSession = new Mock<ICurrentRequestSession>(); requestSession.Setup(x => x.Session).Returns((Session)session); IActiveGoGame activeGame; var game = CreateActiveGame(session.User, null, "adbbdfd999bd4541ba4d742a858dc5f1", out activeGame); var mockHubContext = new MockHubContext("connection #5"); mockHubContext.Client<IHubClient>("5ad61645b24f4f40b55309c96c1a9b81").Setup(x => x.updateGame(It.Is<object>(y => true))).Verifiable(); var newGame = new GoGame(); newGame.BlackPlayer = game.WhitePlayer; newGame.WhitePlayer = null; newGame.GameState = "0123400003430400"; newGame.HubId = "5ad61645b24f4f40b55309c96c1a9b81"; newGame.Id = 23; var goService = new Mock<IGoService>(); goService.Setup(x => x.NewGame()).Returns(newGame).Verifiable(); mockHubContext.Groups.Setup(x => x.Remove(It.Is<string>(y => y.Equals("connection #5")), It.Is<string>(y => y.Equals("adbbdfd999bd4541ba4d742a858dc5f1")))).Verifiable(); mockHubContext.Groups.Setup(x => x.Add(It.Is<string>(y => y.Equals("connection #5")), It.Is<string>(y => y.Equals("5ad61645b24f4f40b55309c96c1a9b81")))).Verifiable(); var hubGoService = new GameOfGoHubService(mockHubContext.Object, requestSession.Object, activeGame, goService.Object, null); hubGoService.NewGame(); mockHubContext.VerifyClients(); mockHubContext.Groups.VerifyAll(); }
public void PassPlayPass_SameColor() { const short n = 3; GoGame game = new GoGame { BoardSize = n }; game.ProposedPlay(new Loc(0, 0)); // 1 game.ProposedPlay(new Loc(n, n)); // 2: PASS RequestResponse response = game.ProposedPlay(new Loc(1, 0)); // 3 Assert.True(!response.Move.StonePlaced.IsWhite); }
public void LibertyCount() { const short n = 3; GoGame game = new GoGame { BoardSize = n }; game.ProposedPlay(new Loc(0, 0)); // X game.ProposedPlay(new Loc(n, n)); // O: PASS game.ProposedPlay(new Loc(0, 1)); // X game.ProposedPlay(new Loc(n, n)); // O: PASS game.ProposedPlay(new Loc(1, 1)); // X // TEST: explicitly check number of groups and each groups stones and breaths. Assert.True(game.blackChains.Count == 1); Assert.True(game.blackChains.First().Liberties.Count == 4); }
public void Disallow_MergeMakesSuicide() { const short n = 3; GoGame game = new GoGame { BoardSize = n }; game.ProposedPlay(new Loc(0, 0)); // X game.ProposedPlay(new Loc(0, 1)); // O game.ProposedPlay(new Loc(2, 0)); // X game.ProposedPlay(new Loc(2, 1)); // O game.ProposedPlay(new Loc(n, n)); // X: PASS game.ProposedPlay(new Loc(1, 1)); // O RequestResponse response = game.ProposedPlay(new Loc(1, 0)); // 1 Assert.True(game.blackChains.Count == 2); Assert.True(game.whiteChains.Count == 1); Assert.True(game.blackChains.Count(chain => chain.Liberties.First().Equals(new Loc(1, 0))) == 2); // 2 black chains with same Liberty Assert.True(response.Reason == ReasonEnum.Suicide); // TEST: Still Black's turn. Assert.True(!game.ProposedPlay(new Loc(1, 2)).Move.StonePlaced.IsWhite); // X }
public void Disallow_StoneConflict() { short n = 2; GoGame game = new GoGame { BoardSize = n }; game.ProposedPlay(new Loc(0, 0)); Assert.True(game.ProposedPlay(new Loc(0, 0)).Reason == ReasonEnum.Conflict); // TEST: It's still White's turn. Assert.True(game.ProposedPlay(new Loc(1, 1)).Move.StonePlaced.IsWhite); }
public void LiveEdge() { short n = 3; GoGame game = new GoGame { BoardSize = n }; game.ProposedPlay(new Loc(0, 1)); Assert.True(game.blackChains.Count == 1); Assert.True(game.blackChains[0].Stones.Count == 1); Assert.True(game.blackChains[0].Liberties.Count == 3); Assert.True(game.blackChains[0].Liberties.Contains(new Loc(0, 0))); Assert.True(game.blackChains[0].Liberties.Contains(new Loc(1, 1))); Assert.True(game.blackChains[0].Liberties.Contains(new Loc(0, 2))); }
public void Disallow_Suicide() { const short n = 3; GoGame game = new GoGame { BoardSize = n }; game.ProposedPlay(new Loc(n, n)); // X: PASS game.ProposedPlay(new Loc(0, 1)); // O game.ProposedPlay(new Loc(n, n)); // X: PASS game.ProposedPlay(new Loc(1, 0)); // O RequestResponse response = game.ProposedPlay(new Loc(0, 0)); // 1 Assert.True(game.blackChains.Count == 0); Assert.True(game.whiteChains.Count == 2); Assert.True(response.Reason == ReasonEnum.Suicide); // TEST: It's still black's turn response = game.ProposedPlay(new Loc(2, 2)); // X Assert.True(!response.Move.StonePlaced.IsWhite); // TEST: White can still play there. response = game.ProposedPlay(new Loc(0, 0)); // O Assert.True(response.Reason == ReasonEnum.Fine); }
public void Kill() { const short n = 3; GoGame game = new GoGame { BoardSize = n }; game.ProposedPlay(new Loc(0, 1)); // X game.ProposedPlay(new Loc(0, 0)); // O game.ProposedPlay(new Loc(1, 0)); // 1 Assert.True(game.blackChains.Count == 2); Assert.True(game.blackChains[0].Stones.Count == 1); Assert.True(game.blackChains[1].Stones.Count == 1); Assert.True(game.whiteChains.Count == 0); Assert.True(game.blackChains.First().Liberties.Count == 3); Assert.True(game.PrisonersTakenByBlack == 1); }
private GameGoBinding(IInvokable onUpdate, IInvokable onDraw) { this.game = new GoGame(onUpdate, onDraw); }
private void JoinGame(GoGame game) { if (game != null) { HubContext.Groups.Add(HubContext.Context.ConnectionId, game.HubId); } UpdateGame(game); }