diff options
author | InigoGutierrez <inigogf.95@gmail.com> | 2023-06-12 20:16:04 +0200 |
---|---|---|
committer | InigoGutierrez <inigogf.95@gmail.com> | 2023-06-12 20:16:04 +0200 |
commit | d4a81490bf1396089eb3dac5955a3a8e4cb26e37 (patch) | |
tree | f96febc7950c2742bc36f04ab13bff56851f2388 /go.py | |
parent | b08408d23186205e71dfc68634021e3236bfb45c (diff) | |
parent | 65ac3a6b050dcb88688cdc2654b1ed6693e9a160 (diff) | |
download | imago-d4a81490bf1396089eb3dac5955a3a8e4cb26e37.tar.gz imago-d4a81490bf1396089eb3dac5955a3a8e4cb26e37.zip |
Diffstat (limited to 'go.py')
-rwxr-xr-x | go.py | 34 |
1 files changed, 29 insertions, 5 deletions
@@ -2,14 +2,17 @@ """Play Go!""" +import sys + from imago.engine.parseHelpers import parseVertex from imago.gameLogic.gameState import GameState -if __name__ == "__main__": +def runGame(): GAMESTATE = GameState(9) + gameEnded = False - while True: + while not gameEnded: GAMESTATE.getBoard().printBoard() @@ -19,11 +22,32 @@ if __name__ == "__main__": move = parseVertex(move, GAMESTATE.size) except Exception as err: print("Invalid move syntax. Example of move: A1") + print() continue + if move == "pass": + + GAMESTATE.playPass() + if GAMESTATE.lastMove.previousMove.isPass: + print("Both players passed: end of the game.") + gameEnded = True + + else: + moveRow = move[0] + moveCol = move[1] + try: + GAMESTATE.playMove(moveRow, moveCol) + except Exception as err: + print(err) + print() - moveRow = move[0] - moveCol = move[1] +if __name__ == "__main__": - GAMESTATE.playMove(moveRow, moveCol) + try: + runGame() + except KeyboardInterrupt as err: + print() + print("Quitting: End of the game.") + print() + sys.exit(0) |