chess playing implemented, minus game over checks

This commit is contained in:
Rudis Muiznieks 2022-04-25 08:27:32 -05:00
parent 38a2854378
commit 6620385196
Signed by: rudism
GPG Key ID: CABF2F86EF7884F9
3 changed files with 8 additions and 13 deletions

View File

@ -34,7 +34,7 @@ def execute(cinput: ControlInput, graphics: Graphics, _):
sunfish.initial, 0, (True,True), (True,True), 0, 0)]
player_color = 'wb'[get_color(hist[-1])]
draw.draw_board(hist[-1] if player_color == "w" else hist[-1].rotate(), player_color)
draw.draw_board(hist[-1], player_color)
state = GameState.MAIN_MENU
menu_index = 0
@ -58,14 +58,10 @@ def execute(cinput: ControlInput, graphics: Graphics, _):
if time.time() - start > MAX_THINKING_SECONDS:
break
hist.append(hist[-1].move(move))
draw.draw_board(hist[-1].rotate(), player_color)
draw.draw_board(hist[-1], player_color)
last_move = move_str(move, player_color == "w")
if score == sunfish.MATE_UPPER:
draw.draw_checkmate(last_move, False)
state = GameState.GAME_OVER
else:
all_moves = dict()
state = GameState.CHOOSE_SRC
all_moves = dict()
state = GameState.CHOOSE_SRC
elif state == GameState.CHOOSE_SRC:
if len(list(all_moves)) == 0:
all_moves = get_all_moves(hist[-1])
@ -105,7 +101,7 @@ def execute(cinput: ControlInput, graphics: Graphics, _):
player_color = "w"
state = GameState.CHOOSE_SRC
hist = [pos]
draw.draw_board(hist[-1], player_color)
draw.draw_board(hist[-1] if player_color == "w" else hist[-1].rotate(), player_color)
elif state == GameState.CHOOSE_SRC:
if key == Button.DIR_D or key == Button.DIR_R:
src_idx += 1
@ -138,7 +134,7 @@ def execute(cinput: ControlInput, graphics: Graphics, _):
draw.draw_board(hist[-1].rotate(), player_color)
state = GameState.THINKING
else:
if key == Button.BTN_A:
if key == Button.BTN_A or key == Button.BTN_B:
state = GameState.MAIN_MENU
def get_all_moves(pos: sunfish.Position):

View File

@ -81,8 +81,7 @@ class Draw:
def draw_board(self, pos: Position, player_color: str):
self._graphics.fill_rect(0, 0, self.BOARD_SIZE, self.BOARD_SIZE, 0)
nb = "".join(pos.board.split())
nb = nb[::-1] if player_color == "b" else nb
nb = "".join(pos.board.split()) if player_color == "w" else "".join(pos.rotate().board.split())[::-1]
c = True
for row in range(8):
for col in range(8):

View File

@ -295,7 +295,7 @@ class Searcher:
# Note, we don't have to check for legality, since we've already done it
# before. Also note that in QS the killer must be a capture, otherwise we
# will be non deterministic.
killer = selfctp_move.get(pos)
killer = self.tp_move.get(pos)
if killer and (depth > 0 or pos.value(killer) >= QS_LIMIT):
yield killer, -self.bound(pos.move(killer), 1-gamma, depth-1, root=False)
# Then all the other moves