Пример #1
0
        public void TestGetPoints()
        {
            var hex = new Hexagon(0, 0);
            var points = hex.GetPoints();
            Assert.AreEqual(6, points.Count, "A hexagon must have 6 points.");

            var msg = "Hexagon is missing a point.";
            Assert.IsTrue(points.Contains(new HexPoint(0, 0, 1, 1, 1, 0)), msg);
            Assert.IsTrue(points.Contains(new HexPoint(0, 0, 1, 0, 0, -1)), msg);
            Assert.IsTrue(points.Contains(new HexPoint(0, 0, 0, -1, -1, -1)), msg);
            Assert.IsTrue(points.Contains(new HexPoint(0, 0, -1, -1, -1, 0)), msg);
            Assert.IsTrue(points.Contains(new HexPoint(0, 0, -1, 0, 0, 1)), msg);
            Assert.IsTrue(points.Contains(new HexPoint(0, 0, 0, 1, 1, 1)), msg);
        }
Пример #2
0
        /// <summary>
        /// Moves the robber to the given hex location and returns a list of players touching that hex (excluding the player moving it.)
        /// </summary>
        public ActionResult<IList<int>> MoveRobber(int player, Hexagon location)
        {
            if (!IsHexagonInBoard(location))
            {
                return new ActionResult<IList<int>>(null, false, string.Format("The hex location {0} is out of bounds.", location));
            }

            if (_robberLocation == location)
            {
                return new ActionResult<IList<int>>(null, false, string.Format("The hex location {0} already contains the robber.", location));
            }

            _robberLocation = location;

            var points = location.GetPoints();
            var buildingsTouching = _buildings.Where(b => points.Contains(b.Key));
            var players = buildingsTouching.Select(b => b.Value.Player).Distinct().ToList();
            players.Sort();
            return new ActionResult<IList<int>>(players, true);
        }