コード例 #1
0
ファイル: Referee.cs プロジェクト: Travis393-Team48/testing
        /*
         * 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;
        }
コード例 #2
0
        public void EmptyBoard()
        {
            string board = "[" +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]," +
                           "[\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"]" +
                           "]";

            JObject jObject = new JObject(
                new JProperty("B", 0),
                new JProperty("W", 0));

            RuleCheckerWrapper.JsonCommand(JToken.Parse(board)).Should().BeEquivalentTo(jObject);
        }
コード例 #3
0
ファイル: Referee.cs プロジェクト: Travis393-Team48/testing
        /* 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");
            }
        }
コード例 #4
0
        //Parse json from a file and run it through BoardWrapper
        //Returns output of BoardWrapper.JsonCommand
        private string TestJson(string filePath)
        {
            string json = ExtractJson(filePath);

            //Parse console input
            List <JToken> jTokenList = ParsingHelper.ParseJson(json);

            List <JToken> finalList = new List <JToken>();

            foreach (JToken jtoken in jTokenList)
            {
                finalList.Add(RuleCheckerWrapper.JsonCommand(jtoken));
            }

            return(JsonConvert.SerializeObject(finalList));
        }
コード例 #5
0
        /* 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");
            }
        }
コード例 #6
0
        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);
        }
コード例 #7
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");
        }