#!/usr/bin/env python import random import game BOARD_SIZE = 14 tiles = game.game_tiles() def can_place( board: game.Board, tile: game.Tile, player: game.Player ) -> list[tuple[int, int]]: placements = [] placements.extend def print_game_state(game_state: tuple[game.Board, list[int], list[int]]): (board, p1tiles, p2tiles) = game_state barr = [] for i in range(BOARD_SIZE): barr.append([]) for j in range(BOARD_SIZE): barr[i].append(board[(j, i)]) for row in barr: print( "".join( [ " " if x == 0 else "X" if x == 1 else "O" if x == 2 else "S" for x in row ] ) ) print("") print(f"Player 1 tiles left: {p1tiles}") print(f"Player 2 tiles left: {p2tiles}") game_state = ( game.Board(), [i for i in range(21)], [i for i in range(21)], ) playing = True player = 1 while playing: moves = [] assert player == 1 or player == 2 gp = game.Player.P1 if player == 1 else game.Player.P2 for tile_idx in game_state[player]: tile = tiles[tile_idx] perms = tile.permutations() for perm in perms: plcs = game_state[0].tile_placements(perm, gp) moves.extend((tile_idx, perm, plc) for plc in plcs) print(f"player {player} has {len(moves)} options") if len(moves) == 0: print(f"No moves left, player {player} lost") playing = False continue (tidx, tile, placement) = random.choice(moves) print( f"player {player} is placing the following tile with index {tidx} at {placement}\n{tile}" ) game_state[0].place(tile, placement, gp) game_state[player].remove(tidx) print_game_state(game_state) if player == 1: player = 2 elif player == 2: player = 1