()
| 27 | |
| 28 | |
| 29 | def main(): |
| 30 | print('''Mancala, by Al Sweigart al@inventwithpython.com |
| 31 | |
| 32 | The ancient two-player, seed-sowing game. Grab the seeds from a pit on |
| 33 | your side and place one in each following pit, going counterclockwise |
| 34 | and skipping your opponent's store. If your last seed lands in an empty |
| 35 | pit of yours, move the opposite pit's seeds into your store. The |
| 36 | goal is to get the most seeds in your store on the side of the board. |
| 37 | If the last placed seed is in your store, you get a free turn. |
| 38 | |
| 39 | The game ends when all of one player's pits are empty. The other player |
| 40 | claims the remaining seeds for their store, and the winner is the one |
| 41 | with the most seeds. |
| 42 | |
| 43 | More info at https://en.wikipedia.org/wiki/Mancala |
| 44 | ''') |
| 45 | input('Press Enter to begin...') |
| 46 | |
| 47 | gameBoard = getNewBoard() |
| 48 | playerTurn = '1' # Player 1 goes first. |
| 49 | |
| 50 | while True: # Run a player's turn. |
| 51 | # "Clear" the screen by printing many newlines, so the old |
| 52 | # board isn't visible anymore. |
| 53 | print('\n' * 60) |
| 54 | # Display board and get the player's move: |
| 55 | displayBoard(gameBoard) |
| 56 | playerMove = askForPlayerMove(playerTurn, gameBoard) |
| 57 | |
| 58 | # Carry out the player's move: |
| 59 | playerTurn = makeMove(gameBoard, playerTurn, playerMove) |
| 60 | |
| 61 | # Check if the game ended and a player has won: |
| 62 | winner = checkForWinner(gameBoard) |
| 63 | if winner == '1' or winner == '2': |
| 64 | displayBoard(gameBoard) # Display the board one last time. |
| 65 | print('Player ' + winner + ' has won!') |
| 66 | sys.exit() |
| 67 | elif winner == 'tie': |
| 68 | displayBoard(gameBoard) # Display the board one last time. |
| 69 | print('There is a tie!') |
| 70 | sys.exit() |
| 71 | |
| 72 | |
| 73 | def getNewBoard(): |
no test coverage detected