コード例 #1
0
ファイル: LocationTest.cs プロジェクト: AnthonySteele/Hex
        public void EqualityTest()
        {
            Location loc1 = new Location(2, 3);
            Location loc2 = new Location(3, 2);
            Location loc1Dup = new Location(2, 3);

            Assert.AreNotEqual(loc1, loc2);

            Assert.AreEqual(loc1, loc1);
            Assert.AreEqual(loc2, loc2);
            Assert.AreEqual(loc1, loc1Dup);

            Assert.IsTrue(loc1 == loc1Dup);
            Assert.IsFalse(loc1 == loc2);

            Assert.IsTrue(loc1.Equals(loc1));
            Assert.IsTrue(loc1.Equals(loc1Dup));
            Assert.IsFalse(loc1.Equals(loc2));

            Assert.IsFalse(loc1.Equals(null));
            Assert.IsFalse(loc1.Equals(3));
            Assert.IsFalse(loc1.Equals("hello"));

            Assert.IsFalse(loc1 != loc1Dup);
            Assert.IsTrue(loc1 != loc2);
        }
コード例 #2
0
ファイル: GoodMovesTests.cs プロジェクト: AnthonySteele/Hex
        public void TestDataMove()
        {
            for (int i = 0; i < 10; i++)
            {
                var insertLoc = new Location(i, i);
                this.goodMoves.AddGoodMove(0, insertLoc);

                Location[] insertOutMoves = this.goodMoves.GetGoodMoves(0);

                // length should be the same as the number inserted
                Assert.IsTrue(this.goodMoves.GetCount(0) == (i + 1), "Failed count at " + i);
                Assert.IsTrue(insertOutMoves.Length == (i + 1));

                // new element at the start
                Assert.IsTrue(insertLoc.Equals(insertOutMoves[0]));

                // first element at the end
                Assert.IsTrue(insertOutMoves[i].Equals(0, 0));
            }

            Location[] outMoves = this.goodMoves.GetGoodMoves(0);
            Assert.IsTrue(outMoves.Length == 10);
            Assert.IsTrue(outMoves[0].Equals(9, 9));

            // bring to front
            this.goodMoves.AddGoodMove(0, new Location(5, 5));

            outMoves = this.goodMoves.GetGoodMoves(0);
            Assert.IsTrue(outMoves.Length == 10);
            Assert.IsTrue(outMoves[0].Equals(5, 5));

            // bring various to front, test all are still present
            for (int i = 9; i >= 0; i--)
            {
                this.goodMoves.AddGoodMove(0, new Location(i, i));
                outMoves = this.goodMoves.GetGoodMoves(0);

                Assert.IsTrue(outMoves.Length == 10);
                Assert.IsTrue(outMoves[0].Equals(i, i));

                IsAllPresentOnce(outMoves);
            }
        }
コード例 #3
0
ファイル: GoodMoves.cs プロジェクト: AnthonySteele/Hex
        /// <summary>
        /// Store a good move at the front of the list for the given depth
        /// Move the rest up
        /// If the good move was in the list but not that the front,
        /// bring it to the front
        /// If there are enough good moves already, one falls off the end
        /// else the count goes up
        /// </summary>
        /// <param name="moveDepth">the depth at which to add</param>
        /// <param name="insertLoc">the locaiton to add</param>
        public void AddGoodMove(int moveDepth, Location insertLoc)
        {
            if (insertLoc.IsNull())
            {
                return;
            }

            if (moveDepth >= this.Depth)
            {
                this.SetDepth(moveDepth + 1);
            }

            Location[] myDepthLocs = this.moves[moveDepth];

            Location currentLoc = insertLoc;

            bool foundInList = false;

            int max = this.count[moveDepth];
            if (max >= GoodMovesCount)
            {
                max = GoodMovesCount - 1;
            }

            for (int index = 0; index <= max; index++)
            {
                Location tempLoc = myDepthLocs[index];

                // insert and move the next move up one
                myDepthLocs[index] = currentLoc;
                currentLoc = tempLoc;

                // if the original inserted loc was in the list, stop moving up
                if ((index < max) && insertLoc.Equals(currentLoc))
                {
                    foundInList = true;
                    break;
                }
            }

            // has the stored move count increased?
            if ((!foundInList) && (this.count[moveDepth] < GoodMovesCount))
            {
                this.count[moveDepth]++;
            }
        }