Example #1
0
 def test_move_logging(self):
     game = Board()
     game.start()
     game.update((4, 1), (4, 2))
     game.display()
     game.next_turn()
     if 'movelog.txt' in os.listdir():
         with open('movelog.txt', 'r') as f:
             line = f.readline()
             self.assertTrue('41' in line and '42' in line)
Example #2
0
 def test_quick_game(self):
     '''Row/col labels, player move, check message'''
     game = Board(debug=True)
     game.start()
     for start, end in [
                        ((4, 1), (4, 2)),
                        ((3, 6), (3, 5)),
                        ((3, 0), (7, 4)),
                        ((5, 6), (5, 5)), # check
                        ((7, 4), (4, 7)), # white win
                        ]:
         game.update(start, end)
         game.display()
         game.next_turn()
Example #3
0
def newgame():
    # Note that in Python, objects and variables
    # in the global space are available to
    # top-level functions
    global game
    game = Board()
    game.start()
    global movehistory
    movehistory = MoveHistory(5)
    ui.board = game.display()
    ui.inputlabel = f'{game.turn} player: '
    ui.errmsg = ""
    ui.btnlabel = 'Move'
    ui.action = '/play'
    # Test code
    # game.move((0, 1), (0, 7))
    # ui.board = game.display()
    # /Test code
    return redirect(url_for('play'))
Example #4
0
from chess import Board, King, Queen, Bishop, Knight, Rook, Pawn

game = Board()
game.start()
while game.winner is None:
    game.display()
    start, end = game.prompt()
    game.update(start, end)
    game.next_turn()
print(f'Game over. {game.winner} player wins!')