Exemplo n.º 1
0
 public void InsertGroupToGroupList(GoGroupClass group_val)
 {
     this.groupArray[this.groupCount] = group_val;
     group_val.SetIndexNumber(this.groupCount);
     this.groupCount++;
     group_val.SetGroupListObject(this);
 }
Exemplo n.º 2
0
        public void AbendGroupList()
        {
            int i = 0;

            while (i < this.groupCount)
            {
                GoGroupClass group = this.groupArray[i];
                if (group == null)
                {
                    this.abendIt("abendGroupList", "null group");
                    return;
                }
                if (group.GroupListObject() != this)
                {
                    this.abendIt("abendGroupList", "groupListObject");
                    return;
                }
                if (group.IndexNumber() != i)
                {
                    this.abendIt("abendGroupList", "index ");
                    return;
                }

                group.AbendGroup();

                int j = i + 1;
                while (j < this.groupCount)
                {
                    group.AbendOnGroupConflict(this.groupArray[j]);
                    j = j + 1;
                }
                i += 1;
            }
        }
Exemplo n.º 3
0
        private int killOtherColorGroups(GoMoveClass move_val, GoGroupClass my_group_val)
        {
            int count;

            count  = this.killOtherColorGroup(my_group_val, move_val.X() - 1, move_val.Y());
            count += this.killOtherColorGroup(my_group_val, move_val.X() + 1, move_val.Y());
            count += this.killOtherColorGroup(my_group_val, move_val.X(), move_val.Y() - 1);
            count += this.killOtherColorGroup(my_group_val, move_val.X(), move_val.Y() + 1);
            return(count);
        }
Exemplo n.º 4
0
 public void RemoveGroupFromGroupList(GoGroupClass group_val)
 {
     this.groupCount--;
     if (group_val.IndexNumber() != this.groupCount)
     {
         this.groupArray[this.groupCount].SetIndexNumber(group_val.IndexNumber());
         this.groupArray[group_val.IndexNumber()] = this.groupArray[this.groupCount];
     }
     this.groupArray[this.groupCount] = null;
 }
Exemplo n.º 5
0
        public void MergeWithOtherGroup(GoGroupClass group2)
        {
            this.debugIt(false, "mergeWithOtherGroup", "");
            int i = group2.minX;

            while (i <= group2.maxX)
            {
                int j = group2.minY;
                while (j <= group2.maxY)
                {
                    if (group2.existMatrix[i, j])
                    {
                        //this.debug(false, "mergeWithOtherGroup", "i=" + i + " j=" + j);
                        if (this.existMatrix[i, j])
                        {
                            this.abendIt("mergeWithOtherGroup", "already exist");
                        }
                        this.existMatrix[i, j] = group2.existMatrix[i, j];
                        this.stoneCount++;

                        group2.existMatrix[i, j] = false;
                        group2.stoneCount--;
                    }
                    j += 1;
                }
                i += 1;
            }
            if (group2.stoneCount != 0)
            {
                this.abendIt("mergeWithOtherGroup", "theStoneCount");
            }

            if (this.maxX < group2.maxX)
            {
                this.maxX = group2.maxX;
            }
            if (this.minX > group2.minX)
            {
                this.minX = group2.minX;
            }
            if (this.maxY < group2.maxY)
            {
                this.maxY = group2.maxY;
            }
            if (this.minY > group2.minY)
            {
                this.minY = group2.minY;
            }

            if (group2.theGroupListObject.GroupArray(group2.indexNumber) != group2)
            {
                this.abendIt("mergeWithOtherGroup", "group2");
            }
        }
Exemplo n.º 6
0
 private void removeDeadGroup(GoGroupClass group)
 {
     group.RemoveDeadStoneFromBoard();
     if (group.MyColor() == GoDefineClass.GO_BLACK_STONE)
     {
         this.blackGroupList().RemoveGroupFromGroupList(group);
     }
     else
     {
         this.whiteGroupList().RemoveGroupFromGroupList(group);
     }
 }
Exemplo n.º 7
0
        private GoGroupClass insertStoneToGroupList(GoMoveClass move_val)
        {
            GoGroupListClass g_list;

            if (move_val.MyColor() == GoDefineClass.GO_BLACK_STONE)
            {
                g_list = this.blackGroupList();
            }
            else if (move_val.MyColor() == GoDefineClass.GO_WHITE_STONE)
            {
                g_list = this.whiteGroupList();
            }
            else
            {
                this.abendIt("insertStoneToGroupList", move_val.MoveInfo());
                return(null);
            }

            GoGroupClass group = g_list.FindCandidateGroup(move_val.X(), move_val.Y());

            if (group == null)
            {
                group = new GoGroupClass(g_list);
                group.InsertStoneToGroup(move_val.X(), move_val.Y(), false);
                g_list.InsertGroupToGroupList(group);
                return(group);
            }

            group.InsertStoneToGroup(move_val.X(), move_val.Y(), false);

            int          dummy_count = 0;
            GoGroupClass group2;

            while (true)
            {
                group2 = g_list.FindOtherCandidateGroup(group, move_val.X(), move_val.Y());
                if (group2 == null)
                {
                    break;
                }
                dummy_count += 1;
                group.MergeWithOtherGroup(group2);
                g_list.RemoveGroupFromGroupList(group2);
            }
            if (dummy_count > 3)
            {
                this.abendIt("insertStoneToGroupList", "dummy_count");
            }
            return(group);
        }
Exemplo n.º 8
0
        public bool StoneExistWithinMe(int x_val, int y_val)
        {
            int i = 0;

            while (i < this.groupCount)
            {
                GoGroupClass group = this.groupArray[i];
                if (group.ExistMatrix(x_val, y_val))
                {
                    return(true);
                }
                i += 1;
            }
            return(false);
        }
Exemplo n.º 9
0
        public GoGroupClass FindOtherCandidateGroup(GoGroupClass group_val, int x_val, int y_val)
        {
            int i = 0;

            while (i < this.groupCount)
            {
                if (this.groupArray[i] != group_val)
                {
                    if (this.groupArray[i].IsCandidateGroup(x_val, y_val))
                    {
                        return(this.groupArray[i]);
                    }
                }
                i += 1;
            }
            return(null);
        }
Exemplo n.º 10
0
 private void markLastDeadInfo1111111111111111(GoGroupClass group_val)
 {
     /*
      * this->theBaseObject->boardObject()->setLastDeadStone(group_val->maxX(), group_val->maxY());
      *
      * if (group_val->maxX() != group_val->minX())
      * {
      *  this->abend("markLastDeadInfo", "bad x");
      * }
      * if (group_val->maxY() != group_val->minY())
      * {
      *  this->abend("markLastDeadInfo", "bad y");
      * }
      * if (!group_val->existMatrix(group_val->maxX(), group_val->maxY()))
      * {
      *  this->abend("markLastDeadInfo", "exist_matrix");
      * }
      */
 }
Exemplo n.º 11
0
        public void AbendOnGroupConflict(GoGroupClass other_group_val)
        {
            int board_size = this.ConfigObject().BoardSize();

            for (int i = 0; i < board_size; i++)
            {
                for (int j = 0; j < board_size; j++)
                {
                    if (this.existMatrix[i, j])
                    {
                        if (other_group_val.existMatrix[i, j])
                        {
                            this.abendIt("AbendOnGroupConflict", "stone  exists in 2 groups");
                            //this->abend("abendOnGroupConflict", "stone (" + i + "," + j + ") exists in 2 groups: (" + this.myColor() + ":" + this.indexNumber() + ":" + this.stoneCount() + ") ("
                            //    + other_group_val.myColor() + ":" + other_group_val.indexNumber() + ":" + other_group_val.stoneCount() + ")");
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        private int killOtherColorGroup(GoGroupClass my_group_val, int x_val, int y_val)
        {
            GoGroupClass his_group;

            if (!this.ConfigObject().IsValidCoordinates(x_val, y_val))
            {
                return(0);
            }

            if (this.BoardObject().BoardArray(x_val, y_val) != my_group_val.HisColor())
            {
                return(0);
            }

            his_group = this.getGroupByCoordinate(x_val, y_val, my_group_val.HisColor());
            if (his_group == null)
            {
                //this.debugIt(true, "killOtherColorGroup", "my_color=" + this.myColor + " his_color=" + this.hisColor);
                this.abendIt("killOtherColorGroup", "null his_group");
                return(0);
            }

            if (his_group.GroupHasAir())
            {
                return(0);
            }

            int dead_count = his_group.StoneCount();

            if ((my_group_val.StoneCount() == 1) && (his_group.StoneCount() == 1))
            {
                his_group.MarkLastDeadInfo();
            }

            this.removeDeadGroup(his_group);
            return(dead_count);
        }
Exemplo n.º 13
0
        public void EnterBattle(GoMoveClass move_val)
        {
            this.debugIt(true, "enterBattle", move_val.MoveInfo());

            this.BoardObject().AddStoneToBoard(move_val.X(), move_val.Y(), move_val.MyColor());
            GoGroupClass my_group = this.insertStoneToGroupList(move_val);

            if (my_group == null)
            {
                this.abendIt("enterBattle", "fail in insertStoneToGroupList");
                return;
            }

            int dead_count = this.killOtherColorGroups(move_val, my_group);

            if (!my_group.GroupHasAir())
            {
                this.removeDeadGroup(my_group);
            }

            if (dead_count != 0)
            {
                if (move_val.MyColor() == GoDefineClass.GO_BLACK_STONE)
                {
                    this.BoardObject().AddBlackCapturedStones(dead_count);
                }
                else if (move_val.MyColor() == GoDefineClass.GO_WHITE_STONE)
                {
                    this.BoardObject().AddWhiteCapturedStones(dead_count);
                }
                else
                {
                    this.abendIt("enterBattle", "bad color");
                }
            }
            this.abendEngine();
        }