aboutsummaryrefslogtreecommitdiff
path: root/go.py
diff options
context:
space:
mode:
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)