示例#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
文件: Board.cs 项目: nerai/GoSharp
 /// <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
文件: Board.cs 项目: nerai/GoSharp
 internal int Capture(Group g)
 {
     foreach (var p in g.Points)
         SetContentAt(p, Content.Empty);
     return g.Points.Count();
 }
示例#5
0
文件: Board.cs 项目: nerai/GoSharp
 /// <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
文件: Board.cs 项目: nerai/GoSharp
 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
文件: Game.cs 项目: davidajulio/hx
 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
文件: Game.cs 项目: davidajulio/hx
 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
文件: Game.cs 项目: davidajulio/hx
 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
文件: Game.cs 项目: davidajulio/hx
 public void RemoveGroup(Group group)
 {
     groups.Remove(group);
 }
示例#11
0
文件: Game.cs 项目: davidajulio/hx
 public void AddGroup(Group group)
 {
     groups.Add(group);
 }