Beispiel #1
0
        /*
         * Simulates a move being made and updates _board_history, _pass_count, and current_player
         * If the move is illegal, throws an exception adn updates _victors
         */
        public void Play(string point)
        {
            try
            {
                RuleCheckerWrapper.Play(_current_player.GetStone(), point, GetBoardHistory());
            }
            catch (RuleCheckerException)
            {
                if (_current_player == _player1)
                {
                    _victors.Add(_player2);
                }
                else
                {
                    _victors.Add(_player1);
                }
                throw new RefereeException("Invalid Play in Referee: an illegal move has been made");
            }

            //update _board_history
            BoardWrapper b = new BoardWrapper(_board_history[0].GetBoard(), _board_history[0].GetSize());

            b.PlaceStone(_current_player.GetStone(), point);
            b.RemoveDeadStones();
            _board_history.Insert(0, b);
            if (_board_history.Count == 4)
            {
                _board_history.RemoveAt(3);
            }

            _pass_count     = 0;
            _current_player = _current_player == _player1 ? _player2 : _player1;
        }
Beispiel #2
0
        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");
        }