import collections
import random
class CheckerBoard(object):
"""
初始化棋盘
"""
def __init__(self, LEN):
self.LEN = LEN
self.position_has_gone = set()
def init_checkerboard(self):
position = []
for i in range(1, self.LEN + 1):
line = []
for j in range(1, self.LEN + 1):
line.append((i, j))
position.append(line)
return position
def init_hourse_position(self):
x = random.randint(1, self.LEN)
y = random.randint(1, self.LEN)
self.position_has_gone.add((x, y))
return (x, y)
def get_next_positions(self, init_position):
next_position = []
x, y = init_position
if x - 1 >= 1:
if y - 2 >= 1:
next_position.append((x - 1, y - 2))
if y + 2 <= self.LEN:
next_pos
马踏棋盘python实现
最新推荐文章于 2023-08-26 23:05:46 发布