more quack for board
This commit is contained in:
parent
ffbc98e1a2
commit
93188fe06b
39
board.py
39
board.py
|
@ -185,6 +185,8 @@ class Board:
|
||||||
# turn and then do something with the second die
|
# turn and then do something with the second die
|
||||||
|
|
||||||
def calc_moves(board, face_value):
|
def calc_moves(board, face_value):
|
||||||
|
return quack.calc_moves(board, player, face_value)
|
||||||
|
|
||||||
idxs_with_checkers = Board.idxs_with_checkers_of_player(board, player)
|
idxs_with_checkers = Board.idxs_with_checkers_of_player(board, player)
|
||||||
if len(idxs_with_checkers) == 0:
|
if len(idxs_with_checkers) == 0:
|
||||||
return [board]
|
return [board]
|
||||||
|
@ -271,39 +273,4 @@ class Board:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def do_move(board, player, move):
|
def do_move(board, player, move):
|
||||||
# Implies that move is valid; make sure to check move validity before calling do_move(...)
|
# Implies that move is valid; make sure to check move validity before calling do_move(...)
|
||||||
|
return quack.do_move(board, player, move)
|
||||||
def move_to_bar(board, to_idx):
|
|
||||||
board = list(board)
|
|
||||||
if player == 1:
|
|
||||||
board[25] -= player
|
|
||||||
else:
|
|
||||||
board[0] -= player
|
|
||||||
|
|
||||||
board[to_idx] = 0
|
|
||||||
return board
|
|
||||||
|
|
||||||
# TODO: Moving in from bar is handled by the representation
|
|
||||||
# TODONE: Handle bearing off
|
|
||||||
|
|
||||||
from_idx = move[0]
|
|
||||||
#print("from_idx: ", from_idx)
|
|
||||||
to_idx = move[1]
|
|
||||||
#print("to_idx: ", to_idx)
|
|
||||||
# pdb.set_trace()
|
|
||||||
board = list(board) # Make mutable copy of board
|
|
||||||
|
|
||||||
# 'Lift' checker
|
|
||||||
board[from_idx] -= player
|
|
||||||
|
|
||||||
# Handle bearing off
|
|
||||||
if to_idx < 1 or to_idx > 24:
|
|
||||||
return tuple(board)
|
|
||||||
|
|
||||||
# Handle hitting checkers
|
|
||||||
if board[to_idx] * player == -1:
|
|
||||||
board = move_to_bar(board, to_idx)
|
|
||||||
|
|
||||||
# Put down checker
|
|
||||||
board[to_idx] += player
|
|
||||||
|
|
||||||
return tuple(board)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user