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