MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / main

Function main

src/gamesbyexample/checkers.py:18–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16
17
18def main():
19 print('Checkers, by Al Sweigart al@inventwithpython.com')
20 gameBoard = getNewBoard() # Create a new checker board.
21 turn = 'O' # O goes first.
22 while True: # Main game loop.
23 displayBoard(gameBoard)
24
25 # Get the player's move and carry it out:
26 srcSpace, dstSpace = askForPlayerMove(gameBoard, turn)
27 if (srcSpace, dstSpace) == (None, None):
28 displayBoard(gameBoard)
29 print(turn + ' is blocked and cannot move.')
30 print(otherCheckers(turn)[1] + ' is the winner!')
31 sys.exit()
32 gameBoard = makeMove(gameBoard, srcSpace, dstSpace)
33
34 if hasLost(gameBoard, otherCheckers(turn)[1]):
35 displayBoard(gameBoard)
36 print(turn + ' is the winner!')
37 sys.exit()
38
39 turn = otherCheckers(turn)[1] # Switch turns to other player.
40
41
42def getNewBoard():

Callers 1

checkers.pyFile · 0.70

Calls 6

getNewBoardFunction · 0.70
displayBoardFunction · 0.70
askForPlayerMoveFunction · 0.70
otherCheckersFunction · 0.70
makeMoveFunction · 0.70
hasLostFunction · 0.70

Tested by

no test coverage detected