|
|
|
@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GameState:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
'''
|
|
|
|
|
有关信息:
|
|
|
|
|
1. 棋盘尺寸为7*9(横向)
|
|
|
|
|
2. 按照以下命名格式对棋盘中的棋子进行标注:
|
|
|
|
|
(b|r)(1|2|3|4|5|6|7)
|
|
|
|
|
3.
|
|
|
|
|
'''
|
|
|
|
|
self.board = [
|
|
|
|
|
['00','00','b7','00','00','00','r1','00','00'],
|
|
|
|
|
['00','b2','00','00','00','00','00','r3','00'],
|
|
|
|
|
['00','00','b4','00','00','00','r5','00','00'],
|
|
|
|
|
['00','00','b6','00','00','00','r6','00','00'],
|
|
|
|
|
['00','00','b5','00','00','00','r4','00','00'],
|
|
|
|
|
['00','b3','00','00','00','00','00','r2','00'],
|
|
|
|
|
['00','00','b1','00','00','00','r7','00','00'],
|
|
|
|
|
]
|
|
|
|
|
self.moveFunctions = {
|
|
|
|
|
"1": self.getMseMoves,
|
|
|
|
|
"2": self.getEagMoves,
|
|
|
|
|
"3": self.getFoxMoves,
|
|
|
|
|
"4": self.getStdMoves,
|
|
|
|
|
"5": self.getStdMoves,
|
|
|
|
|
"6": self.getLionMoves,
|
|
|
|
|
"7": self.getStdMoves,
|
|
|
|
|
}
|
|
|
|
|
self.blue_trap_loc=[(2,0),(3,1),(4,0)]
|
|
|
|
|
self.red_trap_loc=[(3,7),(2,8),(4,8)]
|
|
|
|
|
self.blue_home=(3,0)
|
|
|
|
|
self.red_home=(3,8)
|
|
|
|
|
self.red_to_move=True
|
|
|
|
|
self.conquered=False
|
|
|
|
|
self.MASSACRE=False
|
|
|
|
|
|
|
|
|
|
# 判断特殊位置
|
|
|
|
|
def inWater(self,row,col):
|
|
|
|
|
if row in [1,2,4,5]:
|
|
|
|
|
if col in [3,4,5]:
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
def inTrap(self,row,col,color):
|
|
|
|
|
if color=="blue":
|
|
|
|
|
if (row,col) in self.blue_trap_loc:
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
if (row,col) in self.red_trap_loc:
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
def Eliminate(self,row,col,nxt_row,nxt_col):
|
|
|
|
|
return self.board[nxt_row][nxt_col] == '00' or self.board[nxt_row][nxt_col][0] != self.board[row][col][0] and eval(self.board[row][col][1]) >= eval(self.board[nxt_row][nxt_col][1])
|
|
|
|
|
# 定义移动方式
|
|
|
|
|
def getStdMoves(self,row,col,moves):#输入当前的位置,将可行路径输出给moves
|
|
|
|
|
directions = [(1,0),(0,1),(-1,0),(0,-1)]
|
|
|
|
|
enemy_color = 'b' if self.red_to_move else 'r'
|
|
|
|
|
for direction in directions:
|
|
|
|
|
new_row = row + direction[0]*1
|
|
|
|
|
new_col = col + direction[1]*1
|
|
|
|
|
if 0<=new_row<=8 and 0<=new_col<=6 :
|
|
|
|
|
nxt_piece = self.board[new_row][new_col]
|
|
|
|
|
if nxt_piece == '00' and not self.inWater(new_row,new_col):#如果下一个位置是空的,则可以移动
|
|
|
|
|
moves.append((new_row,new_col))
|
|
|
|
|
elif nxt_piece[0]==enemy_color and not self.inWater(new_row,new_col) and self.Eliminate(row,col,new_row,new_col):#如果是敌方棋子,且不在水里,且可以消除,则添加到可行路径中
|
|
|
|
|
moves.append((new_row,new_col))
|
|
|
|
|
return moves
|
|
|
|
|
def getMseMoves(self,row,col,moves):
|
|
|
|
|
pass
|
|
|
|
|
def getEagMoves(self,row,col,moves):
|
|
|
|
|
pass
|
|
|
|
|
def getFoxMoves(self,row,col,moves):
|
|
|
|
|
pass
|
|
|
|
|
def getLionMoves(self,row,col,moves):
|
|
|
|
|
pass
|
|
|
|
|
# 判断是否胜利
|
|
|
|
|
def conquer(self):
|
|
|
|
|
if self.board[3][0][0] == 'r' or self.board[3][8][0] == 'b':
|
|
|
|
|
self.conquered = True
|
|
|
|
|
return self.conquered
|
|
|
|
|
|