Able to find all legal moves
This commit is contained in:
parent
34264fe8c4
commit
ddc56680f1
32
board.py
32
board.py
|
@ -41,6 +41,38 @@ class Board:
|
|||
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 """
|
||||
------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue
Block a user