Exemplo n.º 1
0
 def test_no_jump(self):
     '''Pieces cannot jump over pieces of same colour'''
     game = Board(debug=True)
     game.add((4, 1), King('white'))
     game.add((4, 4), Rook('white'))
     game.add((4, 6), King('black'))
     game.add((4, 3), Rook('black'))
     game.turn, game.other_turn = 'white', 'black'
     self.assertFalse(game.valid_move((4, 4), (4, 0)))
     self.assertFalse(game.valid_move((4, 3), (4, 7)))
Exemplo n.º 2
0
 def test_add(self):
     board = Board()
     self.assertTrue(all(square == None for square in board.squares()))
     board.add(Color.white, Pawn, Position(3, 4))
     board.add(Color.black, Pawn, Position(6, 6))
     self.assertEqual(Color.white, board.at(Position(3, 4)).color)
     self.assertEqual(Pawn, type(board.at(Position(3, 4))))
     self.assertEqual(Color.black, board.at(Position(6, 6)).color)
     self.assertEqual(Pawn, type(board.at(Position(6, 6))))
     self.assertEqual(2, len(list(board.pieces())))
     for position in board.positions():
         if position not in (Position(3, 4), Position(6, 6)):
             self.assertIsNone(board.at(position))
Exemplo n.º 3
0
class PawnTest(unittest.TestCase):

    def setUp(self):
        self.board = Board()
        self.wpawn = self.board.add(Color.white, Pawn, Position(1,4))
        self.bpawn = self.board.add(Color.black, Pawn, Position(2,3))

    def test_possible_moves(self):
        self.assertListEqual(self.wpawn.possible_moves, [Position(2, 4), Position(3, 4)])
        self.assertListEqual(self.bpawn.possible_moves, [Position(1, 3)])

    def test_possible_attacks(self):
        self.assertListEqual(self.wpawn.possible_attacks, [self.bpawn.position])
        self.assertListEqual(self.bpawn.possible_attacks, [self.wpawn.position])
Exemplo n.º 4
0
class PawnTest(unittest.TestCase):
    def setUp(self):
        self.board = Board()
        self.wpawn = self.board.add(Color.white, Pawn, Position(1, 4))
        self.bpawn = self.board.add(Color.black, Pawn, Position(2, 3))

    def test_possible_moves(self):
        self.assertListEqual(self.wpawn.possible_moves,
                             [Position(2, 4), Position(3, 4)])
        self.assertListEqual(self.bpawn.possible_moves, [Position(1, 3)])

    def test_possible_attacks(self):
        self.assertListEqual(self.wpawn.possible_attacks,
                             [self.bpawn.position])
        self.assertListEqual(self.bpawn.possible_attacks,
                             [self.wpawn.position])
Exemplo n.º 5
0
def gameSetupWithKings():
    game = Board(debug=True)
    game.add((4, 0), King('white'))
    game.add((4, 7), King('black'))
    return game