Able to find all legal moves

This commit is contained in:
Alexander Munch-Hansen 2018-02-05 23:36:32 +01:00
parent 34264fe8c4
commit ddc56680f1
2 changed files with 33 additions and 1 deletions

View File

@ -41,6 +41,38 @@ class Board:
return True 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): def to_s(self):
return """ return """
------------------------------------------ ------------------------------------------

View File

@ -19,7 +19,7 @@ class Human:
def do_move(self, roll): def do_move(self, roll):
print(self.board.to_s()) print(self.board.to_s())
print(self.board.find_legal_moves(self.sym,roll[0]))
cur_state = self.board.get_state() cur_state = self.board.get_state()
print("What to do with the first roll?") print("What to do with the first roll?")