def judge_owner(self,row,col,color,direct): c=[] if direct == 0: if 0 < row < self.__n-1: if 0 not in self.logic_board_state[row * 4 + col]: self.logic_board_owner[row * 4 + col] = color c.append(row * 4 + col) if 0 not in self.logic_board_state[row * 4 + col - 4]: self.logic_board_owner[row * 4 + col - 4] = color c.append(row * 4 + col - 4) elif row == 0: if 0 not in self.logic_board_state[col]: self.logic_board_owner[col] = color c.append(col) elif row == self.__n - 1: if 0 not in self.logic_board_state[row*3+col]: self.logic_board_owner[row*3+col] = color c.append(row*3+col) if direct == 1: if 0 < col < (self.__n-1): if 0 not in self.logic_board_state[row*4 + col]: self.logic_board_owner[row*4 + col] = color c.append(row*4 + col) if 0 not in self.logic_board_state[row*4 + col - 1]: self.logic_board_owner[row*4 + col - 1] = color c.append(row*4 + col - 1) elif col == 0: if 0 not in self.logic_board_state[row*4]: self.logic_board_owner[row*4] = color c.append(row*4) elif col == self.__n - 1: if 0 not in self.logic_board_state[4*row + (col - 1)]: self.logic_board_owner[4*row + (col - 1)] = color c.append(4*row + (col - 1)) return c

时间: 2024-02-14 15:28:46 浏览: 30
这段代码是一个名为 `judge_owner` 的函数,它接收四个参数 `row`、`col`、`color` 和 `direct`。根据 `direct` 的值进行条件判断,函数会根据不同的情况执行相应的操作,并返回一个列表 `c`。 首先,判断 `direct` 的值是否为 0。如果是,会再根据 `row` 的值进行判断。如果满足条件 `0 < row < self.__n-1`,会执行以下操作: - 检查 `self.logic_board_state[row * 4 + col]` 中是否没有 0。如果没有,将 `self.logic_board_owner[row * 4 + col]` 设置为 `color`,并将 `row * 4 + col` 添加到列表 `c` 中。 - 检查 `self.logic_board_state[row * 4 + col - 4]` 中是否没有 0。如果没有,将 `self.logic_board_owner[row * 4 + col - 4]` 设置为 `color`,并将 `row * 4 + col - 4` 添加到列表 `c` 中。 如果 `row` 的值等于 0,会执行以下操作: - 检查 `self.logic_board_state[col]` 中是否没有 0。如果没有,将 `self.logic_board_owner[col]` 设置为 `color`,并将 `col` 添加到列表 `c` 中。 如果 `row` 的值等于 `self.__n - 1`,会执行以下操作: - 检查 `self.logic_board_state[row*3+col]` 中是否没有 0。如果没有,将 `self.logic_board_owner[row*3+col]` 设置为 `color`,并将 `row*3+col` 添加到列表 `c` 中。 如果 `direct` 的值不是 0,会进行第二个条件语句的判断。如果满足条件 `0 < col < (self.__n-1)`,会执行以下操作: - 检查 `self.logic_board_state[row*4 + col]` 中是否没有 0。如果没有,将 `self.logic_board_owner[row*4 + col]` 设置为 `color`,并将 `row*4 + col` 添加到列表 `c` 中。 - 检查 `self.logic_board_state[row*4 + col - 1]` 中是否没有 0。如果没有,将 `self.logic_board_owner[row*4 + col - 1]` 设置为 `color`,并将 `row*4 + col - 1` 添加到列表 `c` 中。 如果 `col` 的值等于 0,会执行以下操作: - 检查 `self.logic_board_state[row*4]` 中是否没有 0。如果没有,将 `self.logic_board_owner[row*4]` 设置为 `color`,并将 `row*4` 添加到列表 `c` 中。 如果 `col` 的值等于 `self.__n - 1`,会执行以下操作: - 检查 `self.logic_board_state[4*row + (col - 1)]` 中是否没有 0。如果没有,将 `self.logic_board_owner[4*row + (col - 1)]` 设置为 `color`,并将 `4*row + (col - 1)` 添加到列表 `c` 中。 最后,函数会返回列表 `c`。

相关推荐

def __next_step(self, x, y): if not self.judge_colory: self.__history += 0 else: self.__history += 1 self.color = 1 if self.__history % 2 == 0 else 2 if self.start_ai_game: if self.ai_color == self.color: row,col = self.ai_stage(self.ai_game()[0],self.ai_game()[1]) else: col = round((x-self.__margin*2)/self.__cell_width) row = round((y-self.__margin*2)/self.__cell_width) stage_row = (y-self.__margin)-(self.__cell_width*row+self.__margin) stage_col = (x-self.__margin)-(self.__cell_width*col+self.__margin) if stage_col < stage_row: self.direct= 1 else: self.direct= 0 else: col = round((x - self.__margin * 2) / self.__cell_width) row = round((y - self.__margin * 2) / self.__cell_width) stage_row = (y - self.__margin) - (self.__cell_width * row + self.__margin) stage_col = (x - self.__margin) - (self.__cell_width * col + self.__margin) if stage_col < stage_row: self.direct = 1 else: self.direct= 0 if self.valide(row, col, self.direct): if self.__history % 4 == 0 or (self.__history + 2) % 4 == 0: self.__game_board.drew_turn(2) else: self.__game_board.drew_turn(1) self.add_logic(row, col, self.color) self.__game_board.draw_chess(row, col, self.color, self.direct) if self.judge_owner(row, col, self.color, self.direct): self.__game_board.drew_turn(self.judge_next(self.color)) for i in self.judge_owner(row, col, self.color, self.direct): x,y=self.draw_owner(i) self.__game_board.drew_owner(self.color, y, x) else: self.__game_board.drew_turn(self.color) self.judge_color(row, col, self.color, self.direct) print(self.logic_board_state) if 0 not in self.logic_board_owner: self.__game_board.pop_win(self.judge_winner())

def get_logic_pos(self,x,y): return (y-self.margin + self.cell_width//2)//self.cell_width, (x-self.margin + self.cell_width//2)//self.cell_width def judge_line(self,row,col,direct,chess_color): c = 1 for i in range(1,6): next_row, next_col = row + direct[0][0] * i, col + direct[0][1] * i if self.matrix[next_row][next_col] == chess_color: c +=1 else: break for i in range(1, 6): next_row, next_col = row + direct[1][0] * i, col + direct[1][1] * i if self.matrix[next_row][next_col] == chess_color: c +=1 else: break return c def judge(self,row,col,chess_color): for direct in [[(-1,0),(1,0)],[(0,-1),(0,1)],[(-1,1),(1,-1)],[(-1,-1),(1,1)]]: if self.judge_line(row,col,direct,chess_color) ==6: return chess_color if len(self.history) == self.n * self.n: return -1 return 0 def deal_with_judge(self, judge_result): if not judge_result: return if judge_result == 1: txt = 'Black Win' elif judge_result == 2: txt = 'White Win' elif judge_result == -1: txt = 'Draw Chess' self.gameboard.draw_box(txt) self.full_matrix(self.n) def put_chess(self,x,y): l = len(self.history) chess_color = (l+1) % 4 // 2+1 if chess_color == self.auto_color: row, col = self.AI.generate_next(self.history, 1 - len(self.history) % 2, chess_color) else: row,col = self.get_logic_pos(x,y) if self.matrix[row][col] == 0: self.history.append((row, col, chess_color)) self.matrix[row][col] = chess_color self.gameboard.drawchess(row, col, chess_color) self.gameboard.draw_now_chess(chess_color) self.deal_with_judge(self.judge(row,col,chess_color)) def full_matrix(self,n): for i in range(self.n): for j in range(self.n): self.matrix[i][j] = 1

最新推荐

recommend-type

node-v18.11.0-headers.tar.xz

Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
recommend-type

JavaScript_跨平台3D场景编辑器基于threejs golang和mongodb桌面和web.zip

JavaScript
recommend-type

JavaScript_如何编写跨平台Nodejs代码.zip

JavaScript
recommend-type

北邮大三物流工程物流信息系统课程设计

北邮大三物流工程物流信息系统课程设计
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

可见光定位LED及其供电硬件具体型号,广角镜头和探测器,实验设计具体流程步骤,

1. 可见光定位LED型号:一般可使用5mm或3mm的普通白色LED,也可以选择专门用于定位的LED,例如OSRAM公司的SFH 4715AS或Vishay公司的VLMU3500-385-120。 2. 供电硬件型号:可以使用常见的直流电源供电,也可以选择专门的LED驱动器,例如Meanwell公司的ELG-75-C或ELG-150-C系列。 3. 广角镜头和探测器型号:一般可采用广角透镜和CMOS摄像头或光电二极管探测器,例如Omron公司的B5W-LA或Murata公司的IRS-B210ST01。 4. 实验设计流程步骤: 1)确定实验目的和研究对象,例如车辆或机器人的定位和导航。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依