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

Function getNewBoard

src/gamesbyexample/chancecheckers.py:48–71  ·  view source on GitHub ↗

Set up a board data structure with empty spaces.

()

Source from the content-addressed store, hash-verified

46
47
48def getNewBoard():
49 """Set up a board data structure with empty spaces."""
50
51 # Keys are spaces (like 'B1'), values are the checker or EMPTY:
52 board = {}
53
54 # Set every space to be empty:
55 for row in range(1, 9):
56 if row % 2 == 0: # Set the spaces on even rows:
57 for column in EVEN_CHECKER_COLUMNS:
58 board[column + str(row)] = EMPTY
59 elif row % 2 == 1: # Set the spaces on odd rows:
60 for column in ODD_CHECKER_COLUMNS:
61 board[column + str(row)] = EMPTY
62
63 # Place the starting pieces for player X at the top:
64 for space in 'B1 D1 F1 H1 A2 C2 E2 G2 B3 D3 F3 H3'.split():
65 board[space] = 'x'
66
67 # Place the starting pieces for player O at the bottom:
68 for space in 'A6 C6 E6 G6 B7 D7 F7 H7 A8 C8 E8 G8'.split():
69 board[space] = 'o'
70
71 return board
72
73
74def displayBoard(board):

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected