马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
之前就一直想写一个人机对战五子棋,陆陆续续脱坑,今天终于实现部分代码,
我更希望渔友们一起使用检测,如果有逻辑错误,或者其他方面错误,给我留言反馈
确认你的python解释器安装好numpy,你可以使用下面命令,安装numpy库
下面是使用demo,以及gomoku文件
gomoku.rar
(165.94 KB, 下载次数: 1)
from core import gomoku
import numpy
class Game:
def __init__(self):
self.board = []
self.ctx = gomoku.create_context()
@property
def cnt_bck(self):
"""Return to the list of statistics for black chess patterns.
function specification::The function returns a list with an index representing the number of pieces of the same color, e.g.
result[3] indicates the number of 572 vectors on the board containing 3 pieces of the same color
"""
return self.ctx.black_counts
@property
def cnt_wht(self):
"""Return to the list of statistics for white chess patterns.
function specification::The function returns a list with an index representing the number of pieces of the same color, e.g.
result[3] indicates the number of 572 vectors on the board containing 3 pieces of the same color
"""
return self.ctx.white_counts
def make_move(self, x: int, y: int, player: int):
"""It takes 0.6825408935546875 s seconds to make a million calls
x: x coordinate
y: y coordinate
function specification:: Drop function, transfer coordinates (x,y) and identity
identifier player [1,-1]. 1 identifies blacks, -1 identifies whites
"""
return self.ctx.make_move(x, y, player)
def undo_move(self):
"""It takes 0.7378938106269836 s seconds to make a million calls
function specification::undo_move does not need to pass parameters, and the data of the previous step is undone
"""
self.ctx.undo_move()
def get_sorted_moves(self, player: int, counts: int = 10):
"""100W calls take 3.1213883638381956 s seconds
function specification::Get the points of the score and sort them according to the score. By default, 10 best hits are returned.
result[i] = {(x,y),score}
"""
return self.ctx.get_sorted_moves(player, counts)
def is_over(self):
"""Whether the game is over or not, Black returns 1 for a win and -1 for a White win. No end returns 0."""
if self.cnt_bck[5]:
return 1
if self.cnt_wht[5]:
return -1
return 0
|