Пример #1
0
 public void TestThatAGroupIsEqualToAnotherWithTheSameGridPoints()
 {
     var gp = new GridPoint(2, 2);
     var group1 = new Group(gp);
     var group2 = new Group(gp);
     Assert.AreEqual(group1, group2);
 }
Пример #2
0
 public void TestExceptGroupsFindsUniqueElementsInAGroup()
 {
     var gp1 = new GridPoint(1, 1);
     var gp2 = new GridPoint(2, 2);
     var gp3 = new GridPoint(3, 3);
     var group1 = new Group(gp1, gp2, gp3);
     var group2 = new Group(gp2);
     var group3 = new Group(gp3);
     var newGroup = group1.ExceptGroups(group2, group3);
     Assert.AreEqual(1, newGroup.Count);
     Assert.IsTrue(newGroup.Contains(gp1));
 }
Пример #3
0
 /// <summary>
 /// Gets the liberty count of the specified group.
 /// </summary>
 /// <param name="group">The group object.</param>
 /// <returns>The number of liberties of the specified group.</returns>
 public int GetLiberties(Group group)
 {
     int libs = 0;
     foreach (var n in group.Neighbours)
     {
         if (GetContentAt(n) == Content.Empty) libs++;
     }
     return libs;
 }
Пример #4
0
 internal int Capture(Group g)
 {
     foreach (var p in g.Points)
         SetContentAt(p, Content.Empty);
     return g.Points.Count();
 }
Пример #5
0
 /// <summary>
 /// Gets the group including the board content at the specified position.
 /// </summary>
 /// <param name="x">The X coordinate of the position.</param>
 /// <param name="y">The Y coordinate of the position.</param>
 /// <returns>A group object containing a list of points.</returns>
 public Group GetGroupAt(int x, int y)
 {
     if (groupCache == null)
     {
         groupCache = new List<Group>();
         groupCache2 = new Group[SizeX, SizeY];
     }
     Group group = groupCache.SingleOrDefault(z => z.Points.Contains(new Point(x, y)));
     if (group == null)
     {
         group = new Group(content[x, y]);
         RecursiveAddPoint(group, x, y);
         groupCache.Add(group);
     }
     return group;
 }
Пример #6
0
 private void RecursiveAddPoint(Group group, int x, int y)
 {
     if (GetContentAt(x, y) == group.Content)
     {
         if (group.ContainsPoint(x, y)) return;
         group.AddPoint(x, y);
         groupCache2[x, y] = group;
         if (x > 0) RecursiveAddPoint(group, x - 1, y);
         if (x < SizeX - 1) RecursiveAddPoint(group, x + 1, y);
         if (y > 0) RecursiveAddPoint(group, x, y - 1);
         if (y < SizeY - 1) RecursiveAddPoint(group, x, y + 1);
     }
     else
     {
         group.AddNeighbour(x, y);
     }
 }
Пример #7
0
 void CommitChanges(int liberties)
 {
     if(Group == null)
     {
         Group = new Group(army);
     }
     Group.Liberties += liberties;
     Group.AddPiece(this);
     Board.Instance[position] = this;
     foreach(PiecePosition piecePosition in position.Neighbours)
     {
         if(Board.Instance[piecePosition] == null)
         {
             continue;
         }
         if(Board.Instance[piecePosition].Group.Army == army && Board.Instance[piecePosition].Group != Group)
         {
             Group.AddGroup(Board.Instance[piecePosition].Group);
         }
         else if(Board.Instance[piecePosition].Group.Army != army)
         {
             Board.Instance[piecePosition].Group.CheckLiberties();
         }
     }
     Group.CheckLiberties();
 }
Пример #8
0
 void CheckNeighbour(Piece neighbour, ref int remaingLiberties)
 {
     if(neighbour == null)
     {
         return;
     }
     if(neighbour.Group.Army != army)
     {
         --neighbour.Group.Liberties;
         --remaingLiberties;
         return;
     }
     Group = neighbour.Group;
     --Group.Liberties;
     --remaingLiberties;
 }
Пример #9
0
 public void AddGroup(Group group)
 {
     foreach(Piece piece in group.Pieces)
     {
         piece.Group = this;
     }
     Liberties += group.Liberties;
     Pieces.AddRange(group.Pieces);
     Army.RemoveGroup(group);
 }
Пример #10
0
 public void RemoveGroup(Group group)
 {
     groups.Remove(group);
 }
Пример #11
0
 public void AddGroup(Group group)
 {
     groups.Add(group);
 }