Last active
November 28, 2016 16:33
-
-
Save countlurk/b48c8c8b79ca60946b5b4ddaaeeccdb8 to your computer and use it in GitHub Desktop.
Tic-Tac-Toe created by Pawtiko - https://repl.it/E4Jf/4
This file contains hidden or 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
from sys import exit | |
''' | |
Key: | |
a1 | a2 | a3 | |
b1 | b2 | b3 | |
c1 | c2 | c3 | |
''' | |
def draw_board(): | |
print(board['a1'],'|',board['a2'],'|',board['a3']) | |
print(board['b1'],'|',board['b2'],'|',board['b3']) | |
print(board['c1'],'|',board['c2'],'|',board['c3']) | |
def ask_move(team): | |
answered = False | |
while answered == False: | |
move = input('Where will you go? ') | |
if move in valid_moves: | |
answered = True | |
valid_moves.remove(move) | |
else: | |
print('That is not a valid move') | |
board[move] = team | |
draw_board() | |
def one_player(): | |
print('One player mode is not yet implemented!') | |
# #Ask what team the player is, and reprompt if the response is invalid | |
# valid = False | |
# | |
# while valid == False: | |
# player_team = input('Will you be X or O? ') | |
# if player_team == 'x' or player_team == 'X': | |
# player_team = 'X' | |
# valid = True | |
# elif player_team == 'o' or player_team == 'O': | |
# player_team = 'O' | |
# valid = True | |
# else: print("Please type either 'x' or 'o'.") | |
# | |
# if player_team == 'X': | |
# ask_move() | |
# | |
# draw_board(a1,a2,a3,b1,b2,b3,c1,c2,c3) | |
def check_win(team): | |
if board['a1'] == team and board['a2'] == team and board['a3'] == team: | |
win(team) | |
if board['b1'] == team and board['b2'] == team and board['b3'] == team: | |
win(team) | |
if board['c1'] == team and board['c2'] == team and board['c3'] == team: | |
win(team) | |
if board['a1'] == team and board['b1'] == team and board['c1'] == team: | |
win(team) | |
if board['a2'] == team and board['b2'] == team and board['c2'] == team: | |
win(team) | |
if board['a3'] == team and board['b3'] == team and board['c3'] == team: | |
win(team) | |
if board['a1'] == team and board['b2'] == team and board['c3'] == team: | |
win(team) | |
if board['a3'] == team and board['b2'] == team and board['c1'] == team: | |
win(team) | |
if len(valid_moves) == 0: | |
print('') | |
print('Draw!') | |
exit() | |
def two_player(): | |
end = False | |
while end == False: | |
ask_move('X') | |
check_win('X') | |
ask_move('O') | |
check_win('O') | |
def win(team): | |
print('') | |
print(team,'wins!') | |
exit() | |
valid_moves = ['a1','a2','a3','b1','b2','b3','c1','c2','c3'] | |
board = {'a1': ' ', 'a2': ' ', 'a3': ' ', 'b1': ' ','b2': ' ', 'b3': ' ', 'c1': ' ', 'c2': ' ', 'c3': ' '} | |
# 1 or 2 players? | |
valid = False | |
while valid == False: | |
players = input('How many players? ') | |
if players == '1': | |
valid = True | |
one_player() | |
if players == '2': | |
valid = True | |
two_player() | |
else: print("Please type either '1' or '2'.") |
This file contains hidden or 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
This is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. | |
In jurisdictions that recognize copyright laws, the author or authors | |
of this software dedicate any and all copyright interest in the | |
software to the public domain. We make this dedication for the benefit | |
of the public at large and to the detriment of our heirs and | |
successors. We intend this dedication to be an overt act of | |
relinquishment in perpetuity of all present and future rights to this | |
software under copyright law. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
OTHER DEALINGS IN THE SOFTWARE. | |
For more information, please refer to <http://unlicense.org/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment