-
Notifications
You must be signed in to change notification settings - Fork 0
/
board.py
60 lines (50 loc) · 1.82 KB
/
board.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from constants import *
def check_boardsize():
"""Checks if the board size is even or odd
Returns True if even, False if odd.
"""
return BOARD_SIZE % 2 == 0
def create_board():
""" Returns an empty board, a list
"""
empty_list = ['']
board = []
for i in range(BOARD_SIZE):
board.append(empty_list * BOARD_SIZE)
return board
def create_and_initialize_board():
""" Creates an empty board and initializes it,
takes the empty board and adds starting chips in the center
"""
board = create_board()
center_index_1 = BOARD_SIZE // 2
center_index_2 = center_index_1 - 1
board[center_index_2][center_index_2] = PLAYER_CHIPS[0]
board[center_index_2][center_index_1] = PLAYER_CHIPS[1]
board[center_index_1][center_index_2] = PLAYER_CHIPS[1]
board[center_index_1][center_index_1] = PLAYER_CHIPS[0]
return board
def print_col_letters():
""" Prints the column identification letters
(A,B,C,..) in the upper side of the board
"""
print(' ' * 4, end='') # Spaces printed for column letter fitting
for i in range(len(create_and_initialize_board())):
print(chr(i + 65), end=' ') # Adds 65 to match ASCII uppercase code
print() # Ends with a new line for board print
def print_board(board):
"""Prints the board, given by parameter (a list)
separated by pipes "|"
"""
print_col_letters()
for index, row in enumerate(board):
if (index + 1) < 10: # Validates if row number is 10
print(' ' + str(index + 1), end=' ') # or more for space fitting
else:
print(index + 1, end=' ')
for col in row:
if col == '':
print('|' + ' ', end='')
else:
print('|' + col, end='')
print('|')