modelscope / agentscope

Start building LLM-empowered multi-agent applications in an easier way.

Home Page:https://modelscope.github.io/agentscope/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

multi-Agent 五子棋游戏时检查黑白方是否 Win 的Bug

Shy2593666979 opened this issue · comments

My Thinks

五子棋当有一方对角线上 或者 横竖线上存在五子连珠时即获胜,应该将黑白方选择的落棋点更新到board中,再去判断是否 Win !

目前你们官方写的是获取到当前Agent落棋点Row 和 Col,根据Row 和 Col判断当前行列上以及对角线是否存在五子连珠,但是忘记当前落棋点也是一个棋子!

Code

文件路径

examples/game_gomoku/code/board_agent.py

Your official code

            if self.check_win(row, col, NAME_TO_PIECE[x["name"]]):
                content = f"The game ends, {x['name']} wins!"
                self.game_end = True
            else:
                # change the board
                self.board[row, col] = NAME_TO_PIECE[x["name"]]

                # check if the game ends
                if self.check_draw():
                    content = "The game ends in a draw!"
                    self.game_end = True
                else:
                    next_player_name = (
                        NAME_BLACK if x["name"] == NAME_WHITE else NAME_WHITE
                    )
                    content = CURRENT_BOARD_PROMPT_TEMPLATE.format(
                        board=self.board2text(),
                        player=next_player_name,
                    )

My updated code

            # change the board
            self.board[row, col] = NAME_TO_PIECE[x["name"]]

            # check if the game ends
            if self.check_draw():
                content = "The game ends in a draw!"
                self.game_end = True
            else:
                next_player_name = (
                    NAME_BLACK if x["name"] == NAME_WHITE else NAME_WHITE
                )
                content = CURRENT_BOARD_PROMPT_TEMPLATE.format(
                    board=self.board2text(),
                    player=next_player_name,
                )
                
            if self.check_win(row, col, NAME_TO_PIECE[x["name"]]):
                content = f"The game ends, {x['name']} wins!"
                self.game_end = True

😊可以定义一个User_Agent来与Model进行人机对弈来检测五子的情况是否结束

感谢纠正!我们会尽快修正这个bug!

FYI:Bug已修复,感谢提供的代码修复方案(同时已将你的GitHub账号加入该PR的co-author list)