May 2019
Intermediate to advanced
542 pages
13h 37m
English
Our game engine object's main responsibility is to keep track of plays and to check whether there is a winner or whether the game is a draw. The players will be represented simply by the 'X' and 'O' strings, and the board will be modeled as a list of nine items that will either be a player or None.
It begins like this:
class TicTacToeEngine(qtc.QObject): winning_sets = [ {0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6} ] players = ('X', 'O') game_won = qtc.pyqtSignal(str) game_draw = qtc.pyqtSignal() def __init__(self): super().__init__() self.board = [None] * 9 self.current_player = self.players[0]
The winning_sets list contains set objects with every combination of board indexes that ...
Read now
Unlock full access