/* Passes the game, updating _pass_count, _current_player, and _board_history * throws and exception if game should end and updates _victors (sorted by lexigraphical order) */ public void Pass() { _pass_count++; _current_player = _current_player == _player1 ? _player2 : _player1; //update _board_history _board_history.Insert(0, _board_history[0]); if (_board_history.Count == 4) { _board_history.RemoveAt(3); } if (_pass_count >= 2) { JObject scores = RuleCheckerWrapper.Score(_board_history[0].GetBoard()); if (scores["B"].ToObject <int>() == scores["W"].ToObject <int>()) { _victors.Add(_player1); _victors.Add(_player2); _victors.Sort(CustomComparators.ComparePlayers); } else if (scores["B"].ToObject <int>() > scores["W"].ToObject <int>()) { _victors.Add(_player1); } else { _victors.Add(_player2); } throw new RefereeException("Game has ended"); } }
/* Passes the game * throws and exception if game should end and updates _victors (sorted by lexigraphical order) */ public void Pass() { _pass_count++; if (_pass_count >= 2) { JObject scores = RuleCheckerWrapper.Score(_board_history[0].GetBoard()); if (scores["B"].ToObject <int>() == scores["W"].ToObject <int>()) { _victors.Add(_player1); _victors.Add(_player2); _victors.Sort(CustomComparators.ComparePlayers); } else if (scores["B"].ToObject <int>() > scores["W"].ToObject <int>()) { _victors.Add(_player1); } else { _victors.Add(_player2); } throw new RefereeException("Game has ended"); } }
public void EmptyBoard() { //one way to create an empty board string[][] board = new string[19][]; for (int i = 0; i < 19; i++) { board[i] = new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " } } ; //another way to create an empty board string[][] aboard = new string[19][] { new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, new string[19] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " } }; JObject jObject = new JObject( new JProperty("B", 0), new JProperty("W", 0)); RuleCheckerWrapper.Score(board).Should().BeEquivalentTo(jObject); }
public void SmallBoards() { string[][] board1 = new string[5][] { new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " } }; JObject jObject = new JObject( new JProperty("B", 0), new JProperty("W", 0)); RuleCheckerWrapper.Score(board1).Should().BeEquivalentTo(jObject); string[][][] boards1 = new string[1][][] { new string[5][] { new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " } } }; RuleCheckerWrapper.Play("B", "1-1", boards1).Should().BeTrue(); string[][][] boards2 = new string[2][][] { new string[5][] { new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " } } , new string[5][] { new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " } } }; RuleCheckerWrapper.Play("W", "1-1", boards2).Should().BeTrue(); string[][][] boards3 = new string[3][][] { new string[5][] { new string[5] { " ", "W", " ", " ", " " }, new string[5] { "W", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " } }, new string[5][] { new string[5] { " ", "W", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " } }, new string[5][] { new string[5] { " ", "W", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " }, new string[5] { " ", " ", " ", " ", " " } } }; Action act = () => RuleCheckerWrapper.Play("B", "1-1", boards3); act.Should().Throw <RuleCheckerException>() .WithMessage("Rule 7a violated in RuleChecker: self sacrifice is not allowed"); }