Exemplo n.º 1
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.º 2
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.º 3
0
        private void processTheWholeMoveList()
        {
            this.BoardObject().ResetBoardObjectData();
            this.FightObject().ResetEngineObjectData();
            this.resetGameObjectPartialData();

            int i = 0;

            while (i < this.theTotalMoves)
            {
                GoMoveClass move = this.theMovesArray[i];
                this.FightObject().EnterBattle(move);
                this.theNextColor = GoDefineClass.GetOppositeColor(move.MyColor());
                i += 1;
            }
        }
Exemplo n.º 4
0
        public void AddNewMoveAndFight(GoMoveClass move_val)
        {
            this.debugIt(true, "AddNewMoveAndFight", "Move = " + move_val.MoveInfo());

            if (move_val.TurnIndex() != this.theTotalMoves + 1)
            {
                this.logitIt("AddNewMoveAndFight", "duplicated move received *****************");
                return;
            }

            if (this.theGameIsOver)
            {
                this.abendIt("AddNewMoveAndFight", "theGameIsOver");
                return;
            }

            this.thePassReceived = false;
            this.BoardObject().ClearLastDeadStone();
            this.insertMoveToMoveList(move_val);
            this.FightObject().EnterBattle(move_val);
            this.theNextColor = GoDefineClass.GetOppositeColor(move_val.MyColor());
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
        public void ParseInputData(string input_data_val)
        {
            int len = input_data_val.Length;//to be deleted

            switch (input_data_val[0])
            {
            case GoProtocolClass.GO_PROTOCOL_MOVE_COMMAND:
                GoMoveClass move = new GoMoveClass(input_data_val.Substring(1, 8));
                this.GameObject().AddNewMoveAndFight(move);
                return;

            case GoProtocolClass.GO_PROTOCOL_BACKWARD_COMMAND:
                this.GameObject().ProcessBackwardMove();
                return;

            case GoProtocolClass.GO_PROTOCOL_DOUBLE_BACKWARD_COMMAND:
                this.GameObject().ProcessDoubleBackwardMove();
                return;

            case GoProtocolClass.GO_PROTOCOL_FORWARD_COMMAND:
                this.GameObject().ProcessForwardMove();
                return;

            case GoProtocolClass.GO_PROTOCOL_DOUBLE_FORWARD_COMMAND:
                this.GameObject().ProcessDoubleForwardMove();
                return;

            case GoProtocolClass.GO_PROTOCOL_PASS_COMMAND:
                return;

            default:
                string err_msg = "command " + input_data_val[1] + " not supported";
                this.abendIt("ParseInputData", err_msg);
                return;
            }
        }
Exemplo n.º 7
0
 private void insertMoveToMoveList(GoMoveClass move_val)
 {
     this.theMovesArray[this.theTotalMoves] = move_val;
     this.theTotalMoves++;
     this.theMaxMove = this.theTotalMoves;
 }