def main(): run = True clock = pygame.time.Clock() game = Game(WIN) start_screen() while run: clock.tick(FPS) if game.winner() != None: print(game.winner()) run = False for event in pygame.event.get(): if event.type == pygame.QUIT: run = False if event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() row, col = get_row_col_from_mouse(pos) game.select(row, col) game.update() end_screen()
def test_checkGameOver(self): x = Game() self.assertFalse(x.checkGameOver()) x = Game() for i in x.victory_cells: x.board.data[x.board.getRowId(i[1]), x.board.getColumnId(i[0])] = 'W' self.assertTrue(x.checkGameOver()) self.assertEqual(x.getWinner(), "WHITE") x = Game() for i in x.victory_cells: x.board.data[x.board.getRowId(i[1]), x.board.getColumnId(i[0])] = 'B' self.assertTrue(x.checkGameOver()) self.assertEqual(x.getWinner(), "BLACK") x = Game() for (i, j) in itertools.product(range(8), range(8)): if i in range(0, 3): x.board.data[i, j] = 'W' if i in range(3, 5): x.board.data[i, j] = 'E' if i in range(5, 8): x.board.data[i, j] = 'B' x.victory_cells = ["a4", "a5", "b4", "b5", "c4"] self.assertTrue(x.checkGameOver()) self.assertEqual(x.getWinner(), "DRAW") x.winner = None x.board.data[3, 7] = 'W' self.assertTrue(x.checkGameOver()) self.assertEqual(x.getWinner(), "WHITE") x.winner = None x.board.data[3, 6] = 'W' x.board.data[4, 1] = 'B' self.assertTrue(x.checkGameOver()) self.assertEqual(x.getWinner(), "WHITE") x.winner = None x.board.data[4, 7] = 'B' self.assertTrue(x.checkGameOver()) self.assertEqual(x.getWinner(), "BLACK")
def test_setNextTurn(self): x = Game() y = Board() x.winner = "DRAW" self.assertFalse(x.setNextTurn("d3")) x.winner = None self.assertTrue(x.setNextTurn("d3")) y.data = np.array([['E', 'E', 'E', 'E', 'E', 'E', 'E', 'E'], ['E', 'E', 'E', 'E', 'E', 'E', 'E', 'E'], ['E', 'E', 'E', 'B', 'E', 'E', 'E', 'E'], ['E', 'E', 'E', 'B', 'B', 'E', 'E', 'E'], ['E', 'E', 'E', 'B', 'W', 'E', 'E', 'E'], ['E', 'E', 'E', 'E', 'E', 'E', 'E', 'E'], ['E', 'E', 'E', 'E', 'E', 'E', 'E', 'E'], ['E', 'E', 'E', 'E', 'E', 'E', 'E', 'E']]) self.assertTrue(np.array_equal(x.board.data, y.data)) self.assertEqual(x.history, ["d3"]) self.assertFalse(x.setNextTurn("e6")) self.assertTrue(x.setNextTurn("NULL")) self.assertEqual(x.getWinner(), "BLACK")