Created
November 1, 2018 16:18
-
-
Save polyspastos/702e05aff3623f3498ecfde79b746e9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def move(side): | |
illegal = 1 | |
while illegal: | |
row = int(input("row: ")) | |
column = int(input("column: ")) | |
if board[row][column] == ' ': | |
if (side % 2) == 1: | |
board[row][column] = 'X' | |
else: | |
board[row][column] = 'O' | |
illegal = 0 | |
else: | |
print("Illegal move.") | |
def draw_board(): | |
os.system('cls') | |
print(" 0 1 2") | |
for r, c in enumerate(board): | |
print(r, c) | |
new_game = 1 | |
a_points = 0 | |
b_points = 0 | |
while new_game: | |
a_points, b_points = b_points, a_points | |
board = [[' ', ' ', ' '], | |
[' ', ' ', ' '], | |
[' ', ' ', ' ']] | |
draw_board() | |
end = 0 | |
side = 1 | |
move_number = 0 | |
player_1 = 'A' if ((a_points + b_points) % 2 == 0) else 'B' | |
player_2 = 'B' if ((a_points + b_points) % 2 == 0) else 'A' | |
while not end: | |
if side % 2 == 1: | |
print("X's turn, who is Player {}.".format(player_1)) | |
else: | |
print("O's turn, who is Player {}.".format(player_2)) | |
move(side) | |
draw_board() | |
# print("\n") | |
for i in range(0, len(board)): | |
# print(board[i]) | |
for j in range(0, len(board[i])): | |
# print(board[i][j]) | |
if board[i][j] != ' ': | |
if board[0][0] == board[1][1] == board[2][2] != ' ': | |
end = 1 | |
elif board[0][2] == board[1][1] == board[2][0] != ' ': | |
end = 1 | |
elif board[0][0] == board[0][1] == board[0][2] != ' ': | |
end = 1 | |
elif board[1][0] == board[1][1] == board[1][2] != ' ': | |
end = 1 | |
elif board[2][0] == board[2][1] == board[2][2] != ' ': | |
end = 1 | |
elif board[0][0] == board[1][0] == board[2][0] != ' ': | |
end = 1 | |
elif board[0][1] == board[1][1] == board[2][1] != ' ': | |
end = 1 | |
elif board[0][2] == board[1][2] == board[2][2] != ' ': | |
end = 1 | |
side += 1 | |
move_number += 1 | |
if move_number == 9: | |
end = 1 | |
if move_number == 9: | |
print("Draw.") | |
a_points += 0.5 | |
b_points += 0.5 | |
elif side % 2 == 1: | |
print("O won.") | |
a_points += 1 | |
elif side % 2 == 0: | |
print("X won.") | |
b_points += 1 | |
print("Tally:\ | |
Player A: {},\n \ | |
Player B: {} points.".format(a_points, b_points)) | |
new_game = input("Would you like to play another game?") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment