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