Пример #1
0
    def test_check(self):
        b = Board(5, 2)
        b._mapa = [[-1, -2, -2, -2, -2], [-2, -2, -2, -2, -2]]
        c = Cell(column=0, row=0, board=b)
        returned = c.check()
        assert_equal(b.state, 'loser')
        assert_equal(c.state_on_board, 100)
        assert_equal(b._mapa[c.row][c.column], 100)
        assert_equal(returned, 100)

        b = Board(5, 2)
        b._mapa = [[100, -2, -2, -2, -2], [-2, -2, -2, -2, -2]]
        c = Cell(column=0, row=0, board=b)
        assert_true(not c.check())

        b = Board(5, 2)
        b._mapa = [[5, -2, -2, -2, -2], [-2, -2, -2, -2, -2]]
        c = Cell(column=0, row=0, board=b)
        assert_true(not c.check())

        b = Board(5, 2)
        b._mapa = [[-2, -2, -2, -2, -2], [-2, -2, -2, -2, -2]]
        c = Cell(column=0, row=0, board=b)
        assert_equal(c.check(), 0)
        assert_equal(b._mapa, [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])

        b = Board(5, 2)
        b._mapa = [[-2, -2, -2, -2, -2], [-2, -2, -2, -2, -1]]
        c = Cell(column=0, row=0, board=b)
        assert_equal(c.check(), 0)
        assert_equal(b._mapa, [[0, 0, 0, 1, -2], [0, 0, 0, 1, -1]])

        b = Board(5, 2)
        b._mapa = [[-2, -2, -2, -2, -2], [-2, -2, -2, -2, -1]]
        c = Cell(column=3, row=1, board=b)
        assert_equal(c.check(), 1)
        assert_equal(b._mapa, [[-2, -2, -2, -2, -2], [-2, -2, -2, 1, -1]])
Пример #2
0
    def test_check(self):
        b = Board(5, 2)
        b._mapa = [[-1, -2, -2, -2, -2], [-2, -2, -2, -2, -2]]
        c = Cell(column=0, row=0, board=b)
        returned = c.check()
        assert_equal(b.state, 'loser')
        assert_equal(c.state_on_board, 100)
        assert_equal(b._mapa[c.row][c.column], 100)
        assert_equal(returned, 100)

        b = Board(5, 2)
        b._mapa = [[100, -2, -2, -2, -2], [-2, -2, -2, -2, -2]]
        c = Cell(column=0, row=0, board=b)
        assert_true(not c.check())

        b = Board(5, 2)
        b._mapa = [[5, -2, -2, -2, -2], [-2, -2, -2, -2, -2]]
        c = Cell(column=0, row=0, board=b)
        assert_true(not c.check())

        b = Board(5, 2)
        b._mapa = [[-2, -2, -2, -2, -2], [-2, -2, -2, -2, -2]]
        c = Cell(column=0, row=0, board=b)
        assert_equal(c.check(),0)
        assert_equal(b._mapa, [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])

        b = Board(5, 2)
        b._mapa = [[-2, -2, -2, -2, -2], [-2, -2, -2, -2, -1]]
        c = Cell(column=0, row=0, board=b)
        assert_equal(c.check(),0)
        assert_equal(b._mapa, [[0, 0, 0, 1, -2], [0, 0, 0, 1, -1]])

        b = Board(5, 2)
        b._mapa = [[-2, -2, -2, -2, -2], [-2, -2, -2, -2, -1]]
        c = Cell(column=3, row=1, board=b)
        assert_equal(c.check(),1)
        assert_equal(b._mapa, [[-2, -2, -2, -2, -2], [-2, -2, -2, 1, -1]])
Пример #3
0
        return var


g = Game()
print(g.board.safe_print())
while g.state == 'in_game':
    kontroler = False
    while kontroler == False:
        try:
            x, y = input('coordinates (row column):').split()
            x = int(x) - 1
            if x < 0 or x > g.board.height - 1:
                raise ValueError
            y = int(y) - 1
            if y < 0 or y > g.board.width - 1:
                raise ValueError
            kontroler = True
        except ValueError:
            print('Error, accepted format: "X Y", try again…')
    c = Cell(row=x, column=y, board=g.board)
    c.check()
    print(g.board.safe_print())
    if g.board.to_win == 0:
        print('WINNER')
        exit()
    if g.board.state == 'loser':
        print('ITS OVER')
        g.state = 'loser'
        print(g.board.print())
        exit()
Пример #4
0
        return var


g = Game()
print(g.board.safe_print())
while g.state == 'in_game':
    kontroler = False
    while kontroler == False:
        try:
            x, y = input('coordinates (row column):').split()
            x = int(x) - 1
            if x < 0 or x > g.board.height - 1:
                raise ValueError
            y = int(y) - 1
            if y < 0 or y > g.board.width - 1:
                raise ValueError
            kontroler = True
        except ValueError:
            print('Error, accepted format: "X Y", try again…')
    c = Cell(row=x, column=y, board=g.board)
    c.check()
    print(g.board.safe_print())
    if g.board.to_win == 0:
        print('WINNER')
        exit()
    if g.board.state == 'loser':
        print('ITS OVER')
        g.state = 'loser'
        print(g.board.print())
        exit()