Commit e2339519 authored by Millian Poquet's avatar Millian Poquet
Browse files

initial commit (doc, codebase)

parents
__pycache__
assr-mi3-go-project
===================
This git repository contains a code base for the software quality go game project done in ASSR-MI3 (IUT2).
This project is meant to be forked so students can develop their own projects.
The code base for this project is free and unencumbered software released into the public domain.
For more information, please refer to <http://unlicense.org/>
'''The board module.
This module is in charge of the very basic handling of the go board.
'''
from collections import namedtuple
from enum import Enum
class Color(Enum):
'''The color of a go board intersection.'''
EMPTY = 0
BLACK = 1
WHITE = 2
Intersection = namedtuple('Intersection', ['x', 'y'])
class Board:
'''The main class to manage a go board.'''
def __init__(self, size: int) -> None:
'''Initialize an empty board of size*size intersections.'''
raise NotImplementedError
def clear(self) -> None:
'''Clear all intersections such that they all become empty.'''
raise NotImplementedError
def load(self, board_state: str) -> None:
'''Sets all intersection colors from board_state.
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
def set_color(self, color: Color, x: int, y: int) -> None:
'''Set the color of the (x,y) intersection of the board.'''
raise NotImplementedError
def color_at(self, x: int, y: int) -> Color:
'''Get the color of the (x,y) intersection of the board.'''
raise NotImplementedError
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.'''
raise NotImplementedError
'''The game module.
This module is in charge of handling a go game,
making sure that the board state is consistent and that player actions are valid.
'''
class InvalidMoveError(Exception):
'''Raised when a player tries to do an invalid move.'''
pass
class Game:
'''The main class to manage a go game.'''
def __init__(self, board_size: int) -> None:
'''Initialize an empty game. Black should be first player to move.'''
raise NotImplementedError
def play_move(self, x: int, y: int) -> None:
'''The current player makes a move.
(x=-1,y=-1) means that the current player skips their turn.
Any other value means that the current player wants to add a stone at (x,y).
This method should raise an InvalidMoveError if the move is invalid.
This method may raise other exceptions (e.g., when playing a move while the game is already finished).
Otherwise, the move should be applied on the board.
'''
raise NotImplementedError
from gomi3.board import *
def test_load():
b = Board(3)
state = '''
---
-w-
b--
'''
b.load(state)
for y in range(3):
for x in range(3):
if ((x,y) == (0,2)):
assert b.color_at(x,y) == Color.BLACK, "(x=0,y=2) should be black"
elif ((x,y) == (1,1)):
assert b.color_at(x,y) == Color.WHITE, "(x=1,y=1) should be white"
else:
assert b.color_at(x,y) == Color.EMPTY
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