Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
zew15101 authored Dec 6, 2019
1 parent 3935ac4 commit 68afa57
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions state.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,22 @@ def piece(self, row, col):
return self.board[row][col]

def removePiece(self, row, col):
self.board[row][col] = None
self.board[row][col] = ' '

def placePiece(self, row, col, color):
if(not self.board[row][col]):
self.board[row][col] = color
else:
print("Error: attempted to place piece on occupied spot")

def movePiece(self, from_position, to_position):
piece_color = piece(from_position[0],from_position[1])
row_range = range(from_position[0], to_position[0])
column_range = range(from_position[1], to_position[1])
for x in row_range:
for y in column_range:
self.removePiece(x,y)
placePiece(to_position[0], to_position[1], piece_color)

def __str__(self):
string = ""
Expand Down Expand Up @@ -143,7 +152,7 @@ def generate_moves(self, board, color):
#Is there a blank space where we need to jump, and is there an opponent's piece to jump over?
if (board[jump_to[0]][jump_to[1]] == ' ' and board[jump_to[0]+1][jump_to[1]] != ' '):
#Append move if possible
possible_moves.append((row, col, jump_to[0], jump_to[1]))
possible_moves.append(((row, col), (jump_to[0], jump_to[1])))
#Update how far it'll jump next time (for multiple jumps)
curr_pos = jump_to
else:
Expand All @@ -157,7 +166,7 @@ def generate_moves(self, board, color):
#Is there a blank space where we need to jump, and is there an opponent's piece to jump over?
if (board[jump_to[0]][jump_to[1]] == ' ' and board[jump_to[0]-1][jump_to[1]] != ' '):
#Append move if possible
possible_moves.append((row, col, jump_to[0], jump_to[1]))
possible_moves.append(((row, col), (jump_to[0], jump_to[1])))
#Update how far it'll jump next time (for multiple jumps)
curr_pos = jump_to
else:
Expand All @@ -172,7 +181,7 @@ def generate_moves(self, board, color):
#Is there a blank space where we need to jump, and is there an opponent's piece to jump over?
if (board[jump_to[0]][jump_to[1]] == ' ' and board[jump_to[0]][jump_to[1]-1] != ' '):
#Append move if possible
possible_moves.append((row, col, jump_to[0], jump_to[1]))
possible_moves.append(((row, col,) (jump_to[0], jump_to[1])))
#Update how far you'll jump next time (for multiple jumps)
curr_pos = jump_to
else:
Expand All @@ -186,13 +195,20 @@ def generate_moves(self, board, color):
#Is there a blank space where we need to jump, and is there an opponent's piece to jump over?
if (board[jump_to[0]][jump_to[1]] == ' ' and board[jump_to[0]][jump_to[1]+1] != ' '):
#Append move if possible
possible_moves.append((row, col, jump_to[0], jump_to[1]))
possible_moves.append(((row, col), (jump_to[0], jump_to[1])))
#Update how far it'll jump next time (for multiple jumps)
curr_pos = jump_to
else:
break
return possible_moves

#Generate successors for moves, needs implemented
def generate_successors(self, board, color):
successors = []
#for move in self.generate_moves(board, color):

return successors

#Evaluation function
def eval(self, board, playerColor, opponentColor):
player_moves = self.generate_moves(playerColor)
Expand Down

0 comments on commit 68afa57

Please sign in to comment.