If I run a game of Paranoia, will knowing the rules lead to a worse experience if/when I participate as a player in the future?

I received the boxed starter set of Paranoia for Christmas, and find myself in the classic dilemma of tabletop players everywhere: do I want to run this game, or try to find someone else to run it, so I can actually play for once?

In Dungeons and Dragons, experience as the DM is generally very good for your abilities as a player, and experience as a player is generally very good for your skill as a DM. However, Paranoia includes a note in their rules that players should not have any understanding of how the rules actually work.

This, to me, suggests that if I run a game of Paranoia, I’ll be setting myself up for a lesser experience as a player.

Am I overthinking this? Is this rule something I should worry about, or should I repeat to myself it’s just a game, and I should really just relax?

Is there efficient way to store data for tower defence game terrain?

I am trying to develop tower defence 3d game using C++ and cocos2d (v 3). So i created 3d terrain and some models. But i don’t know if there is some efficient method or data structure to describle information about road for enemies and places for towers?

Now i can recieve coordinates of the clicked point, but don’t know what to do then, cause i have no data structure for map.

I think i can divide terrain into squares and describe additional file with matrix for all square. But how to sync terrain size with matrix size. Please share you thinking about my case.

Take a look at this mix of TTRPG and board game

What do you think of this experiment?

https://docs.google.com/document/d/1rkb5yVEv-75Vg3E_ruvXPuL9t26agSb5saiRrDn8UI4

”(Les combattantes) This is the game of the back alleys in the big cities, the grasslands at the outskirts of the rural areas, the field of the duel at dawn, the meetup of fighters in the park. The game of swashing blades, rivaling schools and swordplay and the bash of combatants in battle. You are the duelling gentlemen, the nobles, the privateers, the henchmen, the thugs and fighters of the streets.

This is the narrative of duelling. Duelling in the sense of swordmasters, weapon schools, sunset duelling and honor. You are a fighter with an specific style and your school. Combat is both luck and skill.

Manage your opportunities and movement and you will come out on top. Whittle down your opponent’s stamina in order to score hits, chase your opponent away from battle, knock your opponent out and win the duel.

Tic Tac Toe game in Python 3.X using tkinter UI

I am learning to program in Python and as my first project I decided to create a simple Tic Tac Toe game. The game is working properly now and I am wondering if there is anything I could do to improve my code.

Notes:

  1. In my original code I am using pictures on buttons that allow to choose players, to draw moves and to cross out the winning combination. I have changed this in the code that is posted below to improve reviewer experience.

  2. While posting the code here on code review in noticed that some lines of my code exceed 79 char limit – sorry about that. I hope it won’t get in the way too much.

import random  from tkinter import * from tkinter import ttk   def main_window():     root.title('Tic Tac Toe')     remove_widgets()     global frame      frame = ttk.Frame(root, width=250, height=150, relief='groove')     frame.pack_propagate(False)     frame.pack(padx=25, pady=75)      play = ttk.Button(frame, text='Play', command=lambda: play_menu(do=0))     play.pack(side='top', pady=(50, 0))      qb = ttk.Button(frame, text="Quit", command=root.destroy)     qb.pack(side='top', pady=(0, 50))   def play_menu(do):     root.title('Tic Tac Toe')     remove_widgets()     if do == 'redeclare':     redeclare_vars()      global frame      label = ttk.Label(root, text='Choose your side', font=('French Script MT', 20))     label.pack(side='top', pady=(25, 0))      frame = ttk.Frame(root, width=250, height=150, relief='groove')     frame.pack_propagate(False)     frame.pack(padx=25, pady=25)      player_x = ttk.Button(frame, text='X', command=lambda: game(pl='X'))     player_x.grid(column=0, row=0, padx=(5, 0), pady=(5, 0))      player_o = ttk.Button(frame, text='O', command=lambda: game(pl='O'))     player_o.grid(column=1, row=0, padx=(0, 5), pady=(5, 0))      back = ttk.Button(frame, text='Back', command=main_window)     back.grid(column=0, row=1, sticky=(E, W), padx=(5, 5), pady=(0, 5), columnspan=2)   def game(pl=None):     root.title('Tic Tac Toe')     remove_widgets()      global frame, canvas, player, computer, move, stop_game      frame = ttk.Frame(root, width=650, height=700)     frame.pack_propagate(False)     frame.pack()      canvas = Canvas(frame, width=600, height=600)     canvas.pack(side='top', pady=(25, 0))      restart = ttk.Button(frame, text='Restart', command=lambda: play_menu(do='redeclare'))     restart.pack(side='bottom', pady=20)      draw_board()     canvas.bind('<Button-1>', square_selector)      if pl == 'X':         player = 'X'         computer = 'O'         move = 'player'     elif pl == 'O':         player = 'O'         computer = 'X'         move = 'computer'         computer_move()   def remove_widgets():     for widget in root.winfo_children():         widget.destroy()   def square_status_lib(square):     global statusLib, player     status = None      if player == 'X':         status = 'X'     elif player == 'O':         status = 'O'     statusLib[square-1] = status   def square_selector(event):     if 1 <= event.x <= 199:         if 1 <= event.y <= 199:             player_move(square=1)     elif 1 <= event.x <= 199:         if 201 <= event.y <= 399:             player_move(square=2)     elif 1 <= event.x <= 199:         if 401 <= event.y <= 599:             player_move(square=3)     elif 201 <= event.x <= 399:         if 1 <= event.y <= 199:             player_move(square=4)     elif 201 <= event.x <= 399:         if 201 <= event.y <= 399:             player_move(square=5)     elif 201 <= event.x <= 399:         if 401 <= event.y <= 599:             player_move(square=6)     elif 401 <= event.x <= 599:         if 1 <= event.y <= 199:             player_move(square=7)     elif 401 <= event.x <= 599:         if 201 <= event.y <= 399:             player_move(square=8)     elif 401 <= event.x <= 599:         if 401 <= event.y <= 599:             player_move(square=9)   def computer_move():     global move, x1, y1, x2, y2     status, a = 0, 0      while status is not None:         a = random.randint(1, 9)         status = statusLib[a-1]         x1, y1, x2, y2 = squareLib[a - 1][0], squareLib[a - 1][1], squareLib[a - 1][2], squareLib[a - 1][3]     if computer == 'X':         draw_move()         statusLib[a-1] = 'X'     elif computer == 'O':         draw_move()         statusLib[a-1] = 'O'     end_game()     if not stop_game:         move = 'player'   def player_move(square):     global x1, y1, x2, y2, move, squareLib, stop_game      if statusLib[square-1] is None:         x1, y1, x2, y2 = squareLib[square-1][0], squareLib[square-1][1], squareLib[square-1][2], squareLib[square-1][3]         draw_move()         square_status_lib(square=square)         end_game()         if not stop_game:             move = 'computer'             computer_move()   def draw_move():     global player, x1, y1, x2, y2, canvas, move      if move == 'player':         if player == 'X':             canvas.create_line(x1, y1, x2, y2)             canvas.create_line(x1, y2, x2, y1)         elif player == 'O':             canvas.create_oval(x1, y1, x2, y2)     elif move == 'computer':         if computer == 'X':             canvas.create_line(x1, y1, x2, y2)             canvas.create_line(x1, y2, x2, y1)         elif computer == 'O':             canvas.create_oval(x1, y1, x2, y2)   def draw_board():     global canvas     canvas.create_line(0, 200, 600, 200)     canvas.create_line(0, 400, 600, 400)     canvas.create_line(200, 0, 200, 600)     canvas.create_line(400, 0, 400, 600)   def check_end_game():     global tie, stop_game, fin      if statusLib[0] == statusLib[1] == statusLib[2] == 'X' or statusLib[0] == statusLib[1] == statusLib[2] == 'O':         stop_game, fin = True, 1     elif statusLib[3] == statusLib[4] == statusLib[5] == 'X' or statusLib[3] == statusLib[4] == statusLib[5] == 'O':         stop_game, fin = True, 2     elif statusLib[6] == statusLib[7] == statusLib[8] == 'X' or statusLib[6] == statusLib[7] == statusLib[8] == 'O':         stop_game, fin = True, 3     elif statusLib[0] == statusLib[3] == statusLib[6] == 'X' or statusLib[0] == statusLib[3] == statusLib[6] == 'O':         stop_game, fin = True, 4     elif statusLib[1] == statusLib[4] == statusLib[7] == 'X' or statusLib[1] == statusLib[4] == statusLib[7] == 'O':         stop_game, fin = True, 5     elif statusLib[2] == statusLib[5] == statusLib[8] == 'X' or statusLib[2] == statusLib[5] == statusLib[8] == 'O':         stop_game, fin = True, 6     elif statusLib[2] == statusLib[4] == statusLib[6] == 'X' or statusLib[2] == statusLib[4] == statusLib[6] == 'O':         stop_game, fin = True, 7     elif statusLib[0] == statusLib[4] == statusLib[8] == 'X' or statusLib[0] == statusLib[4] == statusLib[8] == 'O':         stop_game, fin = True, 8     elif all(k is not None for k in statusLib):         stop_game, tie, fin = True, True, 0     else:         stop_game, fin = False, 0   def end_game():     global stop_game, tie, canvas     check_end_game()     text = ''      if stop_game:         canvas.unbind('<Button-1>')         if move == 'player' and not tie:             text = 'You win'         elif move == 'computer' and not tie:             text = 'You lose'         elif tie:             text = 'It\'s a tie'          finisher()         canvas.create_text(300, 300, text=text, font=('French Script MT', 50), fill='#000000')      elif not stop_game:         pass   def finisher():     global fin     x3, y3, x4, y4 = 0, 0, 0, 0      if fin != 0:         if fin == 1:             x3, y3, x4, y4 = 100, 100, 100, 500         elif fin == 2:             x3, y3, x4, y4 = 300, 100, 300, 500         elif fin == 3:             x3, y3, x4, y4 = 500, 100, 500, 500         elif fin == 4:             x3, y3, x4, y4 = 100, 100, 500, 100         elif fin == 5:             x3, y3, x4, y4 = 100, 300, 500, 300         elif fin == 6:             x3, y3, x4, y4 = 100, 500, 500, 500         elif fin == 7:             x3, y3, x4, y4 = 100, 500, 500, 100         elif fin == 8:             x3, y3, x4, y4 = 100, 100, 500, 500         canvas.create_line(x3, y3, x4, y4)     elif fin == 0:         pass   def redeclare_vars():     global statusLib, myVal, x1, x2, y1, y2, canvas, move, fin, stop_game, tie     statusLib = []     myVal = None     for l in range(0, 9):         statusLib.append(myVal)     x1, y1, x2, y2, canvas, move, fin = 0, 0, 0, 0, None, '', 0     stop_game, tie = False, False   root = Tk() root.minsize(width=300, height=300)  statusLib = [] myVal = None for i in range(0, 9):     statusLib.append(myVal) x1, y1, x2, y2, canvas, move, fin = 0, 0, 0, 0, None, '', 0 stop_game, tie = False, False game_mode = IntVar()  squareLib = [              [20, 20, 180, 180],              [20, 220, 180, 380],              [20, 420, 180, 580],              [220, 20, 380, 180],              [220, 220, 380, 380],              [220, 420, 380, 580],              [420, 20, 580, 180],              [420, 220, 580, 380],              [420, 420, 580, 580]             ]  main_window() root.mainloop() 

I also do have some specific questions about what I could change:

  1. I have noticed that many tkinter applications posted on the internet as examples make use of classes. Is there any specific reason to do that? tkinter applications do seem to work fine without that and the code gets shorter without classes.

  2. In my app I am clearing the main tkinter window from any widgets whenever I go to a different menu. It seems a little bit strange to destroy and recreate objects while moving between screens, but I couldn’t figure out a different solution. Is my approach a good practice?

  3. Should I create main() function to wrap up all the remaining code at the bottom of the program?

C# Unity Object Pooling (for a shooter game)

I am currently developing a Bullet Hell (shoot-em-up) game for my school project.
I have implemented Object Pooling for my game to recycle mainly bullets. (Though I could use it to recycle enemies in the future if I do need to.)

Currently I have tested this object pooling on bullet and it has worked.
I am looking to receive feedback about my code in order to see if I can do anything about it to make it more efficient and cleaner.

ObjectPool.cs

using System; using System.Collections.Generic; using UnityEngine; using System.Linq;  public class ObjectPool : Singleton<ObjectPool> {      private List<GameObject> objectPool;      private void Awake() {         objectPool = new List<GameObject>();     }      /// <summary>     /// Add a gameobject to the object pool.     /// </summary>     /// <param name="objToPool">The gameobject to add to the object pool.</param>     /// <param name="deactivateObj">Deactivate this gameobject upon storing into the object pool.</param>     public void AddToPool(GameObject objToPool, bool deactivateObj = true) {         objectPool.Add(objToPool);          // If we need to deactivate this gameobject.         if (deactivateObj) {             // Set it to not active.             objToPool.SetActive(false);         }     }      /// <summary>     /// Fetch a gameobject from the pool, with the gameobject containing the desired component.     /// </summary>     /// <typeparam name="T">The type of the component.</typeparam>     /// <param name="removeFromPool">True if the fetched gameobject needs to be removed from the pool.</param>     /// <returns>The respective gameobject. (Null if none is found)</returns>     public GameObject FetchObjectByComponent<T>(bool removeFromPool = true) where T : MonoBehaviour {         GameObject fetchedObject = null;          // Foreach game object in the object pool         foreach (var gameObj in objectPool) {             // If this gameobject has the desired component.             if (gameObj.GetComponent<T>() != null) {                 // Fetch this object.                 fetchedObject = gameObj;                 // End loop (an object with the desired component is found.)                 break;             }         }          // If an object is fetched and we need to remove it from the pool.         if (fetchedObject != null && removeFromPool) {             // Remove the fetched object from the pool.             objectPool.Remove(fetchedObject);         }          return fetchedObject;     }      /// <summary>     /// Fetch an array of gameobjects that contains the desired component.     /// </summary>     /// <typeparam name="T">The type of the component the gameobject must contain.</typeparam>     /// <param name="maxSize">The max size of the array returned. (Negative for limitless)</param>     /// <param name="removeFromPool">True to remove the respective fetched gameobject from the object pool.</param>     /// <returns>The respective fetched game objects.</returns>     public GameObject[] FetchObjectsByComponent<T>(int maxSize = -1, bool removeFromPool = true) where T : MonoBehaviour {          List<GameObject> temp = new List<GameObject>();          // Loop through the object pool as long as the size limit it not reached.         for (int i = 0; i < objectPool.Count && i < maxSize; ++i) {             // If this current object contains the desired component.             if (objectPool[i].GetComponent<T>() != null) {                 // Add to the temporary list                 temp.Add(objectPool[i]);             }         }          var fetchedObjects = temp.ToArray();          // If we need to remove the fetched objects from the object pool, remove.         if (removeFromPool) {             RemoveObjectsFromPool(fetchedObjects);         }          return fetchedObjects;     }      /// <summary>     /// Fetch an array of gameobject based on the given condition.     /// </summary>     /// <param name="condition">The condition to check on when fetching gameobjects.</param>     /// <param name="maxSize">The maximum size of the array returned. (Negative for limitless.)</param>     /// <param name="removeFromPool">True to remove the respective fetched gameobject from the object pool.</param>     /// <returns>The respective fetched game objects.</returns>     public GameObject[] FetchObjectsByCondition(Func<GameObject, bool> condition, int maxSize = -1, bool removeFromPool = true) {         // Fetch all the matching objects.         var fetchedObjects = objectPool.Where(condition).ToArray();          // If an array size limit is given.         if (maxSize >= 1) {             List<GameObject> temp = new List<GameObject>();              // Loop through the fetched objects, adding to the list as long as the list stays in it's given size limit.             for (int i = 0; i < fetchedObjects.Length && i < maxSize; ++i) {                 temp.Add(fetchedObjects[i]);             }              fetchedObjects = temp.ToArray();         }          // If we need to remove the fetched objects from the object pool         if (removeFromPool) {             RemoveObjectsFromPool(fetchedObjects);         }          return fetchedObjects;     }      #region Util      private void RemoveObjectsFromPool(GameObject[] objectsToRemove) {         // For each given object.         foreach (var gameObject in objectsToRemove) {             // Remove the given object from the object pool.             objectPool.Remove(gameObject);         }     }      #endregion } 

I am currently using Unity 2018.3.1f1, if that matters.

Need a simple UX game for workshop [on hold]

I’m looking for a real world example of UX which can be used in a short workshop I’m running. I was hoping to find some sort of game where I could split the teams into small groups, give them a time limit to perform some simple tasks, then show the results.

My audience is mainly people who know very little at all about UX. Does anyone know of a simple, real world usability problem which can be described to the audience so they can think in a way related to UX principals? Ideally, I’d like to get them working in teams to highlight the need for collaborative thinking.

All ideas welcome. (Sorry if this question is a bit outside the norm.)

dice game for two players (Nea)

The rules:

  • The points rolled on each player’s dice are added to their score.

• If the total is an even number, an additional 10 points are added to their score.

• If the total is an odd number, 5 points are subtracted from their score.• If they roll a double, they get to roll one extra die and get the number of points rolled added to their score.

• The score of a player cannot go below 0 at any point.• The person with the highest score at the end of the 5 rounds wins.

• If both players have the same score at the end of the 5 rounds, they each roll 1 die and whoever gets the highest score wins (this repeats until someone wins)

import pickle import random import time  print("") print("welcome to the dice game") print("")  with open('users.pickle', 'rb') as f:     users = pickle.load(f)  print(users)   def login():      logged_in = False      username = input('please enter username: ')      while not logged_in:          if username in users:             password = input("enter password: ")             if password == users[username]:                 print("access granted")                 logged_in = True          else:             print("access denied")             exit()      return username   print("  ")  rounds = 0   def roll():     die1 = random.randint(1, 7)     die2 = random.randint(1, 7)     change = 10 if (die1 + die2) % 2 == 0 else -5     points = die1 + die2 + change     if die1 == die2:         points += random.randint(1, 6)     return points   def game():     player1_points = 0     player2_points = 0     for i in range(1, 6):         player1_points += roll()         print(f'After this round user1 you now have: {player1_points} Points')         # time.sleep(1)         player2_points += roll()         print(f'After this round user2 you now have: {player2_points} Points')      player1_tiebreaker = 0     player2_tiebreaker = 0     if player1_points == player2_tiebreaker:         while player1_tiebreaker == player2_tiebreaker:             player1_tiebreaker = random.randint(1, 6)             player2_tiebreaker = random.randint(1, 6)      player2_win = (player2_points + player2_tiebreaker)     player1_win = (player1_points + player1_tiebreaker) \      return (player1_points, player1_win), (player2_points, player2_win)   def add_winner(winner):      with open('Winner.txt', 'a') as i:         i.write(','.join(map(str, winner)))         i.write('\n')   def get_leaderboard():     with open('Leaderboard.txt', 'r+') as g:         return [line.replace('\n', '') for line in g.readlines()]   def update_leaderboard(leaderboard, winner):     for idx, item in enumerate(leaderboard):         if item.split(',')[1] == winner[1] and int(item.split(',')[0]) < int(winner[0]):             leaderboard[idx] = '{}, {}'.format(winner[0], winner[1])         else:             pass     leaderboard.sort(reverse=True)   def save_leaderboard(leaderboard):     with open('Leaderboard.txt', 'r+') as h:         for item in leaderboard:             h.write(f'{item}\n')   def main():     user1 = login()     user2 = login()      (player1, player1_win), (player2, player2_win) = game()      if player1_win:         winner = [player1, user1]     else:         winner = [player2, user2]      print("Well done: ", winner[1], "you won with", winner[0], "Points")      add_winner(winner)     leaderboard = get_leaderboard()     update_leaderboard(leaderboard, winner)     save_leaderboard(leaderboard)   if __name__ == '__main__':     main() 

Frame limiting in an SDL game

I am a relatively novice programmer, and I am taking steps into graphics programming. I am writing a quick pong clone and want to cap the FPS to save system resources. This is how I have implemented this (I’ve omitted other code for brevity)

#include <stdio.h> #include <stdbool.h> #include "SDL.h" #include "Windows.h" #define WIN32_LEAN_AND_MEAN   #define FPS 30   Uint32 starttime, endtime, deltatime;  int main() {  //initialize SDL and do other stuff  //start game loop  timeBeginPeriod(1);  while (appisrunning)  {  starttime = GetTickCount();     SDL_PollEvent(&event);     if (event.type == SDL_QUIT)     {         SDL_DestroyRenderer(renderer);         SDL_DestroyWindow(window);         SDL_Quit();         appisrunning = false;         break;     }  // render stuff here  endtime = GetTickCount();     if (endtime > starttime)     {         deltatime = endtime - starttime;     }     else // handles wraparound     {         deltatime = ((2 ^ 32) - starttime) + endtime;     }     if (deltatime > (1000 / FPS)) {}      else     {         Sleep((1000 / FPS) - deltatime);     }  }  timeEndPeriod(1);  return 0; } 

I use timeBeginPeriod(1) in an effort to give Sleep() a ~1ms resolution. According to the MSDN documentation, this function sets the timer resolution system wide and can result in higher CPU usage as the scheduler has to switch tasks more often (if I understand correctly).

Is this the right approach for this task? What feedback do you have for me?

Repetitive Tic-Tac-Toe AI game with Python 3

I have a text based Tic-Tac-Toe game with a simple AI element that will take winning moves and block losing moves. The one piece of criticism I received was that I was ‘hard coding’ too much. I can see this, for example, in check_computer_win. How can I use a dictionary to cut down on hard coding? What are some of the best ways I can solve my repetition problem?

#! python  """ This my Tic Tac Toe game with python.  2019-01-10  """  import random import sys  board = [1,2,3,4,5,6,7,8,9] open_boxes = 9 human_letter = '' opp_letter = '' winner = False can_block = False  def choose_letter():       global human_letter     global opp_letter     human_letter = input('Please choose "x" or "o": ').lower()     if human_letter == 'x':         opp_letter = 'o'     elif human_letter == 'o':         opp_letter = 'x'     else:         print('Please choose again.')         choose_letter()  def show_board():     print (board[0], '|', board[1], '|', board[2])     print ("----------")     print (board[3], '|', board[4], '|', board[5])     print ("----------")     print (board[6], '|', board[7], '|', board[8])     print (" ")  def checkLine(char, first, second, third):     if board[first] == char and board[second] == char and board[third] == char:         return True  def checkAll(char):     if checkLine(char,0,1,2):         return True     if checkLine(char,3,4,5):         return True     if checkLine(char,6,7,8):         return True     if checkLine(char,0,3,6):         return True     if checkLine(char,1,4,7):         return True     if checkLine(char,2,5,8):         return True     if checkLine(char,0,4,8):         return True     if checkLine(char,2,4,6):         return True  def computer_move():         global open_boxes         if open_boxes > 0:             check_computer_win()             if not winner:                 block_human_win()                 if not can_block:                     opp_move = random.randint(0,8)                     if board[opp_move] != 'o' and board[opp_move] != 'x':                         open_boxes -= 1                         board[opp_move] = opp_letter                         print('Computer\'s turn')                         print('Computer is thinking...')                         print('\n')                         show_board()                                 else:                         computer_move()         else:             print('--DRAW--')             play_again()  def check_computer_win():     #check for a top horizontal win     if board[0] == opp_letter and board[1] == opp_letter:         if board[2] != human_letter:             board[2] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[0] == opp_letter and board[2] == opp_letter:         if board[1] != human_letter:             board[1] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[1] == opp_letter and board[2] == opp_letter:         if board[0] != human_letter:             board[0] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     #check for a middle horizontal win     if board[3] == opp_letter and board[4] == opp_letter:         if board[5] != human_letter:             board[5] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[3] == opp_letter and board[5] == opp_letter:         if board[4] != human_letter:             board[4] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[4] == opp_letter and board[5] == opp_letter:         if board[3] != human_letter:             board[3] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     #check for a bottom horizontal win     if board[6] == opp_letter and board[7] == opp_letter:         if board[8] != human_letter:             board[8] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[6] == opp_letter and board[8] == opp_letter:         if board[7] != human_letter:             board[7] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[7] == opp_letter and board[8] == opp_letter:         if board[6] != human_letter:             board[6] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     #check for a left vertical win     if board[0] == opp_letter and board[3] == opp_letter:         if board[6] != human_letter:             board[6] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[0] == opp_letter and board[6] == opp_letter:         if board[3] != human_letter:             board[3] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[3] == opp_letter and board[6] == opp_letter:         if board[0] != human_letter:             board[0] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     #check for a left vertical win     if board[0] == opp_letter and board[3] == opp_letter:         if board[6] != human_letter:             board[6] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[0] == opp_letter and board[6] == opp_letter:         if board[3] != human_letter:             board[3] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[3] == opp_letter and board[6] == opp_letter:         if board[0] != human_letter:             board[0] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     #check for a middle vertical win     if board[1] == opp_letter and board[4] == opp_letter:         if board[7] != human_letter:             board[7] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[1] == opp_letter and board[7] == opp_letter:         if board[4] != human_letter:             board[4] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[4] == opp_letter and board[7] == opp_letter:         if board[1] != human_letter:             board[1] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     #check for a right vertical win     if board[2] == opp_letter and board[5] == opp_letter:         if board[8] != human_letter:             board[8] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[2] == opp_letter and board[8] == opp_letter:         if board[5] != human_letter:             board[5] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[5] == opp_letter and board[8] == opp_letter:         if board[2] != human_letter:             board[2] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     #check for a left to right diagonal win     if board[0] == opp_letter and board[4] == opp_letter:         if board[8] != human_letter:             board[8] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[4] == opp_letter and board[8] == opp_letter:        if board[0] != human_letter:             board[0] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()      if board[0] == opp_letter and board[8] == opp_letter:         if board[4] != human_letter:             board[4] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     #check for a right to left diagonal win     if board[2] == opp_letter and board[4] == opp_letter:         if board[6] != human_letter:             board[6] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[4] == opp_letter and board[6] == opp_letter:         if board[2] != human_letter:             board[2] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()     if board[2] == opp_letter and board[6] == opp_letter:         if board[4] != human_letter:             board[4] = opp_letter             winner = True             print ("--COMPUTER WINS--")             show_board()             play_again()  def block_human_win():     global open_boxes     #Block top horizontal win     if board[0] == human_letter and board[1] == human_letter:         if board[2] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[2] = opp_letter             show_board()             human_first()     if board[0] == human_letter and board[2] == human_letter:         if board[1] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[1] = opp_letter             show_board()             human_first()     if board[1] == human_letter and board[2] == human_letter:         if board[0] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[0] = opp_letter             show_board()             human_first()     #Block middle horizontal win     if board[3] == human_letter and board[4] == human_letter:         if board[5] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[5] = opp_letter             show_board()             human_first()     if board[3] == human_letter and board[5] == human_letter:         if board[4] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[4] = opp_letter             show_board()             human_first()     if board[4] == human_letter and board[5] == human_letter:         if board[3] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[3] = opp_letter             show_board()             human_first()     #Block bottom horizontal win     if board[6] == human_letter and board[7] == human_letter:         if board[8] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[8] = opp_letter             show_board()             human_first()     if board[6] == human_letter and board[8] == human_letter:         if board[7] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[7] = opp_letter             show_board()             human_first()     if board[7] == human_letter and board[8] == human_letter:         if board[6] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[6] = opp_letter             show_board()             human_first()     #Block left vertical win     if board[0] == human_letter and board[3] == human_letter:         if board[6] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[6] = opp_letter             show_board()             human_first()     if board[0] == human_letter and board[6] == human_letter:         if board[3] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[3] = opp_letter             show_board()             human_first()     if board[3] == human_letter and board[6] == human_letter:         if board[0] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[0] = opp_letter             show_board()             human_first()     #Block middle vertical win     if board[1] == human_letter and board[4] == human_letter:         if board[7] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[7] = opp_letter             show_board()             human_first()     if board[1] == human_letter and board[7] == human_letter:         if board[4] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[4] = opp_letter             show_board()             human_first()     if board[4] == human_letter and board[7] == human_letter:         if board[1] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[1] = opp_letter             show_board()             human_first()     #Block right vertical win     if board[2] == human_letter and board[5] == human_letter:         if board[8] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[8] = opp_letter             show_board()             human_first()     if board[2] == human_letter and board[8] == human_letter:         if board[5] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[5] = opp_letter             show_board()             human_first()     if board[5] == human_letter and board[8] == human_letter:         if board[2] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[2] = opp_letter             show_board()             human_first()     #Block left to right diagonal win     if board[0] == human_letter and board[4] == human_letter:         if board[8] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[8] = opp_letter             show_board()             human_first()     if board[0] == human_letter and board[8] == human_letter:         if board[4] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[4] = opp_letter             show_board()             human_first()     if board[4] == human_letter and board[8] == human_letter:         if board[0] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[0] = opp_letter             show_board()             human_first()     #Block right to left diagonal win     if board[2] == human_letter and board[4] == human_letter:         if board[6] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[6] = opp_letter             show_board()             human_first()     if board[2] == human_letter and board[6] == human_letter:         if board[4] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[4] = opp_letter             show_board()             human_first()     if board[4] == human_letter and board[6] == human_letter:         if board[2] != opp_letter:             can_block = True             open_boxes -= 1                     print('Computer is thinking...')             print('Computer blocks your winning move.')             board[2] = opp_letter             show_board()             human_first()  def human_first():     can_block = False     global open_boxes     if open_boxes > 0:         while True:             move = input('Please pick a number from 1 - 9: ')             if move.isdigit():                 move = int(move) - 1             else:                 print('Sorry, please pick a number from 1 - 9: ')                 human_first()             winner = False              if board[move] != 'x' and board[move] != 'o':                 board[move] = human_letter                 open_boxes -= 1                 show_board()              else:                 print('\n')                 print('Sorry that space is taken. Try again')                 print('\n')                 show_board()                 human_first()              if checkAll(human_letter) == True:                 winner = True                 print ("--HUMAN WINS--")                 print ('\n')                 play_again()                 break;              computer_move()              if checkAll(opp_letter) == True:                 winner = True                 print ("--COMPUTER WINS--")                 print ('\n')                 play_again()                 break;     else:         print('--DRAW--')         play_again()  def computer_first():     global open_boxes     if open_boxes > 0:         computer_move()         while True:             move = input('Please pick a number from 1 - 9: ')             if move.isdigit():                 move = int(move) - 1             else:                 print('Sorry, please pick a number from 1 - 9: ')                 human_first()              winner = False              if board[move] != 'x' and board[move] != 'o':                 board[move] = human_letter                 open_boxes -= 1                 show_board()             else:                 print('\n')                 print('Sorry that space is taken. Try again')                 print('\n')                 show_board()                 human_first()              if checkAll(human_letter) == True:                 winner = True                 print ("--HUMAN WINS--")                 print ('\n')                 play_again()                 break;              computer_move()              if checkAll(opp_letter) == True:                 winner = True                 print ("--COMPUTER WINS--")                 print ('\n')                 play_again()                 break;     else:         print('--DRAW--')         play_again()  def who_goes_first():     global board     global open_boxes     open_boxes = 9     print ('Welcome to Tic Tac Toe!This is your game board: ')     print ('\n')     show_board()     choose_letter()     print ('\n')     print('The first player will be chosen at random.')     print('...')     first = random.randint(0,1)     if first == 1:         print('Human goes first')         human_first()     else:         print('Computer goes first')         computer_first()  def play_again():     global board     board = [1,2,3,4,5,6,7,8,9]     print('Do you want to play again? Y/N: ')     answer = input().lower()     if answer in ('y','ye','yes'):         who_goes_first()     elif answer in ('n','no'):         print('Hope you enjoyed the game!')         sys.exit()     else:         print('Sorry, I didn\'t get that..')         play_again()    who_goes_first()