Advertisement
Guest User

Tic-Tac-Toe - V1.0

a guest
Dec 9th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. import os
  2.  
  3. def init_board():
  4.     """Returns an empty 3-by-3 board (with zeros)."""
  5.     board = [["-","A","B","C"],[1,0,0,0],[2,0,0,0],[3,0,0,0]]
  6.     return board
  7.  
  8.  
  9. def get_move(board, player):
  10.     """Returns the coordinates of a valid move for player on board."""
  11.     row, col = 0, 0
  12.     return row, col
  13.  
  14.  
  15. def get_ai_move(board, player):
  16.     """Returns the coordinates of a valid move for player on board."""
  17.     row, col = 0, 0
  18.     return row, col
  19.  
  20.  
  21. def mark(board, player, row, col):
  22.     """Marks the element at row & col on the board for player."""
  23.     pass
  24.  
  25.  
  26. def has_won(board, player):
  27.     """Returns True if player has won the game."""
  28.     return False
  29.  
  30.  
  31. def is_full(board):
  32.     """Returns True if board is full."""
  33.     return False
  34.  
  35.  
  36. def print_board(board):
  37.     """Prints a 3-by-3 board on the screen with borders."""
  38.     print("\n")
  39.     for i in board:
  40.         for j in i:
  41.             print(j, end = " ")
  42.         print()
  43.    
  44.  
  45.  
  46. def print_result(winner):
  47.     """Congratulates winner or proclaims tie (if winner equals zero)."""
  48.     pass
  49.  
  50.  
  51. def tictactoe_game(mode='HUMAN-HUMAN'):
  52.     board = init_board()
  53.     # use get_move(), mark(), has_won(), is_full(), and print_board() to create game logic
  54.     print_board(board)
  55.     row, col = get_move(board, 1)
  56.     mark(board, 1, row, col)
  57.  
  58.     winner = 0
  59.     print_result(winner)
  60.  
  61.  
  62. def main_menu():
  63.     os.system("clear")
  64.     print(f"""
  65. Welcome to our Tic-Tac-Toe game!
  66. Please select a game mode:
  67. 1. Human vs Human
  68. 2. Human vs AI
  69. 3. AI vs AI1
  70. 4. Quit Game
  71. """)
  72.     x = input("")
  73.     if x == "1":
  74.         tictactoe_game('HUMAN-HUMAN')
  75.  
  76.  
  77. if __name__ == '__main__':
  78.     main_menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement