Skip to content

Commit 0bb8d8e

Browse files
committed
PCC12
1 parent 09c7681 commit 0bb8d8e

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

12/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Code Challenge 12 - Build a Tic-tac-toe Game
2+
3+
Instructions [here](http://pybit.es/codechallenge12.html).
4+
5+
Previous challenges and About [here](http://pybit.es/pages/challenges.html).

12/tictactoe-template.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
DEFAULT = '_' # or ' '
2+
VALID_POSITIONS = list(range(1, 10)) # could number board: 7-8-9, 4-5-6, 1-2-3
3+
WINNING_COMBINATIONS = (
4+
(7, 8, 9), (4, 5, 6), (1, 2, 3),
5+
(7, 4, 1), (8, 5, 2), (9, 6, 3),
6+
(1, 5, 9), (7, 5, 3),
7+
)
8+
9+
10+
class TicTacToe:
11+
12+
def __init__(self):
13+
'''Constructor, below worked well for us ...'''
14+
self.board = [None] + len(VALID_POSITIONS) * [DEFAULT] # skip index 0
15+
16+
def __str__(self):
17+
'''Print the board'''
18+
pass
19+
20+
# TODOS:
21+
# display board in __str__ (clearing screen)
22+
# have at least an is_win method to exit game
23+
# num turns = len(VALID_POSITIONS) so might not need is_draw (tie) method
24+
# have method(s) to get user input and validate
25+
# if playing against computer (AI) calculate next best move (algorithm)
26+
# update board upon each turn
27+
28+
29+
if __name__ == "__main__":
30+
while True:
31+
game = TicTacToe()
32+
# take turn
33+
# make move
34+
# check win - break
35+
#
36+
# ask if another game, if n - break

0 commit comments

Comments
 (0)