Commit ab750804 authored by Nathan Demary's avatar Nathan Demary
Browse files

Merge branch 'nathan' into 'main'

Release 0.2.0

See merge request !1
parents 0ad5f6d0 feaa4cc5
Pipeline #88819 failed with stage
in 21 seconds
{
"restructuredtext.confPath": ""
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
This module is in charge of the very basic handling of the go board.
'''
from array import array
from collections import namedtuple
from enum import Enum
......@@ -20,13 +21,17 @@ class Board:
'''The main class to manage a go board.'''
def __init__(self, size: int) -> None:
'''Initialize an empty board of size*size intersections.'''
tableau = [[0 for i in range(19)] for j in range(19)]
self.tableau = [[Color(0) for x in range(size)] for y in range(size)]
self.size = size
raise NotImplementedError
def get_tableau(self) -> array:
return self.tableau
def clear(self) -> None:
'''Clear all intersections such that they all become empty.'''
raise NotImplementedError
for x in range(self.size):
for y in range(self.size):
self.set_color(Color(0), x, y)
def load(self, board_state: str) -> None:
'''Sets all intersection colors from board_state.
......@@ -34,17 +39,33 @@ class Board:
board_state is a string that contains size*size characters (excluding spacing characters).
each character represents the color of an intersection ('-', 'b' or 'w').
'''
raise NotImplementedError
board = board_state.strip().replace(" ", "").splitlines()
if len(board) == self.size:
for line in board:
for char in line:
if char == "-":
self.set_color(Color.EMPTY, board.index(line), line.index(char))
if char == "b":
self.set_color(Color.BLACK, board.index(line), line.index(char))
if char == "w":
self.set_color(Color.WHITE, board.index(line), line.index(char))
else:
raise SyntaxError("Input format not valid")
def set_color(self, color: Color, x: int, y: int) -> None:
'''Set the color of the (x,y) intersection of the board.'''
raise NotImplementedError
self.tableau[x][y] = color
def color_at(self, x: int, y: int) -> Color:
'''Get the color of the (x,y) intersection of the board.'''
raise NotImplementedError
current_color = self.tableau[x][y]
if current_color == Color(0):
return Color(0)
if current_color == Color(1):
return Color(1)
if current_color == Color(2):
return Color(2)
def stone_group_at(self, x: int, y: int) -> [Intersection]:
'''Get the maximum-sized stone group that starts from the (x,y) intersection of the board.'''
......
......@@ -19,3 +19,27 @@ def test_load():
assert b.color_at(x,y) == Color.WHITE, "(x=1,y=1) should be white"
else:
assert b.color_at(x,y) == Color.EMPTY
def test_load2():
print(Board(3).get_tableau())
board = ['--b', '-bw', 'b--']
for line in board:
for char in line:
print(board.index(line), line.index(char))
def test_tableau():
tab = Board(3)
tab.set_color(Color(1), 1, 2)
if tab.color_at(1, 2) != Color(1):
raise ValueError('Board.set_color() is not correctly implemented')
if tab.get_tableau() is None:
raise ValueError('Board.get_tableau() is not correctly implemented')
if tab.clear() is not None:
raise ValueError('Board.clear() is not correctly implemented')
if __name__ == "__main__":
test_tableau()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment