diff --git a/aima/games.py b/aima/games.py index d22b2e6..f77b0ce 100644 --- a/aima/games.py +++ b/aima/games.py @@ -7,7 +7,7 @@ from collections import namedtuple import numpy as np -from utils import vector_add +from .utils import vector_add GameState = namedtuple('GameState', 'to_move, utility, board, moves') StochasticGameState = namedtuple('StochasticGameState', 'to_move, utility, board, moves, chance') diff --git a/board.py b/board.py index d3bc460..0b92b77 100644 --- a/board.py +++ b/board.py @@ -4,7 +4,6 @@ import numpy as np from icecream import ic - class CellType(Enum): """ Possible board cell types @@ -25,6 +24,17 @@ class CheckerType(Enum): BLACK = 2 KING = 3 + def __str__(self): + match self: + case CheckerType.EMPTY: + return "EMPTY" + case CheckerType.WHITE: + return "WHITE" + case CheckerType.BLACK: + return "BLACK" + case CheckerType.KING: + return "KING" + class Cell: """ Represents a cell in the board grid @@ -334,4 +344,20 @@ class Board: board_copy.blacks = self.blacks.copy() board_copy.king = self.king - return board_copy \ No newline at end of file + return board_copy + + def to_string_grid(self): + """ + Converts the board's grid to a 2D matrix of strings representing the + checker in each cell (EMPTY, WHITE, KING or BLACK) + + :return: a 2D matrix of strings + """ + + output = [[""] * 9] * 9 + + for i in range(9): + for j in range(9): + output[i][j] = str(self.grid[i,j].checker) + + return output \ No newline at end of file diff --git a/main.py b/main.py index ac5499c..9459945 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ from argparse import ArgumentParser from icecream import ic +from Tablut import Tablut from board import Board from connect import Connection, get_player_port from player import RandomPlayer @@ -46,6 +47,7 @@ def main(): b = Board() b.print_grid() + print(b.to_string_grid()) player = RandomPlayer(role, b) @@ -66,6 +68,8 @@ def main(): 4) update board with M' """ + tablut_game = Tablut() + if role == "BLACK": new_state = conn.receive_new_state() b.update_state(new_state)