aboutsummaryrefslogtreecommitdiff
path: root/go.py
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2023-06-12 20:16:04 +0200
committerInigoGutierrez <inigogf.95@gmail.com>2023-06-12 20:16:04 +0200
commitd4a81490bf1396089eb3dac5955a3a8e4cb26e37 (patch)
treef96febc7950c2742bc36f04ab13bff56851f2388 /go.py
parentb08408d23186205e71dfc68634021e3236bfb45c (diff)
parent65ac3a6b050dcb88688cdc2654b1ed6693e9a160 (diff)
downloadimago-master.tar.gz
imago-master.zip
Merge branch 'devel'HEADmaster
Diffstat (limited to 'go.py')
-rwxr-xr-xgo.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/go.py b/go.py
index cf0a673..7580c2b 100755
--- a/go.py
+++ b/go.py
@@ -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)