diff --git a/board.py b/board.py index 6f67ed4..b4ffee8 100644 --- a/board.py +++ b/board.py @@ -39,7 +39,39 @@ class Board: return False elif ((self.state[to][0] == sym or self.state[to][0] == " ") or (self.state[to][0] == self.switch(sym) and self.state[to][1] == 1)) and self.state[from_][0] == sym: return True + + + + def find_pieces_for_player(self,sym): + idxs = [] + for idx, pip in enumerate(self.state): + if pip[0] == sym: + idxs.append(idx) + return idxs + + def find_legal_moves(self,sym,roll): + # Find all pips with things on them belonging to the player + # Iterate through each index and check if it's a possible move given the roll + # If player is O, then check for idx + roll + # If player is X, then check for idx - roll + # Rewrite this, it's shit. + idxs_with_thing = self.find_pieces_for_player(sym) + print(idxs_with_thing) + legal_moves = [] + if sym == "O": + for index in idxs_with_thing: + from_ = index + to = index+roll + if self.check_move([from_,to], sym, roll): + legal_moves.append([from_,to]) + else: + for index in idxs_with_thing: + from_ = index + to = index-roll + if self.check_move([from_,to], sym, roll): + legal_moves.append([from_,to]) + return legal_moves def to_s(self): return """ diff --git a/hooman.py b/hooman.py index 140291c..f78c8a8 100644 --- a/hooman.py +++ b/hooman.py @@ -19,7 +19,7 @@ class Human: def do_move(self, roll): print(self.board.to_s()) - + print(self.board.find_legal_moves(self.sym,roll[0])) cur_state = self.board.get_state() print("What to do with the first roll?")