定义棋盘
board = [
['車', '馬', '象', '士', '将', '士', '象', '馬', '車'],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', '炮', ' ', ' ', ' ', ' ', ' ', '炮', ' '],
['兵', ' ', '兵', ' ', '兵', ' ', '兵', ' ', '兵'],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
['卒', ' ', '卒', ' ', '卒', ' ', '卒', ' ', '卒'],
[' ', '砲', ' ', ' ', ' ', ' ', ' ', '砲', ' '],
['車', '馬', '象', '士', '将', '士', '象', '馬', '車']
]
定义棋子类
class Chess:
def __init__(self, name, color, position):
self.name = name
self.color = color
self.position = position
def move(self, x, y):
self.position = (x, y)
def __str__(self):
return self.color + self.name
创建棋子
red_chess = [
Chess('車', '红', (0, 0)),
Chess('馬', '红', (0, 1)),
Chess('象', '红', (0, 2)),
Chess('士', '红', (0, 3)),
Chess('将', '红', (0, 4)),
Chess('士', '红', (0, 5)),
Chess('象', '红', (0, 6)),
Chess('馬', '红', (0, 7)),
Chess('車', '红', (0, 8)),
Chess('炮', '红', (2, 1)),
Bz:后面还没调试完,等我回来补充