示例#1
0
 def play(self) -> int:
     board = Board()
     last_x = None
     last_y = None
     while board.round <= MAX_ROUND:
         current_color = board.next_color
         (x, y) = self.players[current_color].play(last_x, last_y)
         if x == -1 and y == -1:
             self.viewer.player_undoes()
             board.undo()
             (last_x, last_y) = (-1, -1)
         else:
             if 0 > x > 4 or 0 > y > 4:
                 raise RuleViolation("out of bounds move")
             if board.field(x, y, 4) != EMPTY:
                 raise RuleViolation("already full at {},{}".format(x, y))
             is_winning = board.move(x, y)
             LOG.debug("player {} plays to {},{}".format(
                 current_color, x, y))
             self.viewer.player_plays(x, y)
             if is_winning:
                 LOG.debug("player {} wins!".format(current_color))
                 self.viewer.finish(board.winning_coords())
                 return current_color
             (last_x, last_y) = (x, y)
     LOG.debug("game ended in a draw")
     self.viewer.finish([])
     return EMPTY
示例#2
0
def test_tostr():
    board = Board()
    board.move(0, 0)
    board.move(0, 0)
    board.move(0, 0)
    board.move(1, 0)
    board.move(3, 3)
    print("\n")
    print(board)
示例#3
0
def test_alternating_players():
    board = Board()
    assert board.field(0, 0, 0) == EMPTY
    assert board.field(1, 1, 0) == EMPTY
    board.move(0, 0)
    assert board.field(0, 0, 0) == RED
    assert board.field(1, 1, 0) == EMPTY
    board.move(1, 1)
    assert board.field(0, 0, 0) == RED
    assert board.field(1, 1, 0) == BLUE
    assert board.round == 2
示例#4
0
 def __init__(self, viewer):
     self.viewer = viewer
     self.board = Board()
     self.play_both_sides = False
示例#5
0
 def __init__(self):
     self.board = Board()
示例#6
0
def test_win_forward2():
    board = Board()
    for i in range(3, 0, -1):
        assert not board.move(i, 3-i)
        assert not board.move(i, 3-i)
    assert board.move(0, 3)
示例#7
0
def test_win_backward2():
    board = Board()
    for i in range(3):
        assert not board.move(i, 3-i)
        assert not board.move(i, 3-i)
    assert board.move(3, 0)