Write code to play a Tic-tac-toe tournament. Tic-tac toe is a game for two players who take turns marking the spaces with Xs and Os in a 3x3 grid. The purpose of the game is to place three of your marks in a horizontal, vertical or diagonal.

Answers

Answer 1

Answer:

Explanation:

The following code is written in Python and is a full Two player tic tac toe game on a 3x3 grid that is represented by numbers per square.

# Making all of the main methods of the game

board = [0,1,2,

        3,4,5,

        6,7,8]

win_con = [[0,1,2],[3,4,5],[6,7,8],

           [0,3,6],[1,4,7],[2,5,8],

           [0,4,8],[2,4,6]] # possible 3-in-a-rows

def show():

   print(board[0],'|',board[1],'|',board[2])

   print('----------')

   print(board[3],'|',board[4],'|',board[5])

   print('----------')

   print(board[6],'|',board[7],'|',board[8])

def x_move(i):

   if board[i] == 'X' or board[i] == 'O':

       return print('Already taken!')

   else:

       del board[i]

       board.insert(i,'X')

def o_move(i):

   if board[i] == 'X' or board[i] == 'O':

       return print('Already taken!')

   else:

       del board[i]

       board.insert(i,'O')  

 

# Creating the main loop of the game

while True:

   turn_num = 1

   board = [0,1,2,3,4,5,6,7,8]

   print('Welcome to Tic-Tac-Toe!')

   print('AI not implemented yet.')

   while True:

       for list in win_con: #check for victor

           xnum = 0

           onum = 0

           for num in list:

               if board[num] == 'X':

                   xnum += 1

               elif board[num] == 'O':

                   onum += 1

               else:

                   pass

           if xnum == 3 or onum == 3:

               break

       if xnum == 3 or onum == 3: # break loops

           break

       if turn_num > 9: # Check if there are any more moves available

           break

       show()

       if turn_num % 2 == 1:

           print('X\'s turn.')

       else:

           print('O\'s turn.')

       move = int(input('Choose a space. '))

       if turn_num % 2 == 1:

           x_move(move)

       else:

           o_move(move)

       turn_num += 1

   if xnum == 3:  #If game ends

       print('X Won!')

   elif onum == 3:

       print('O Won!')

   else:

       print('Draw!')

   play_again = input('Play again? Y or N ')

   if play_again == 'Y' or play_again == 'y':

       continue

   else:

       break


Related Questions

Write a python program that: - Defines a tuple of 5 integer numbers - prints the tuple - Appends a new value to the end of the tuple - prints the tuple again Please note that appending a new value to a tuple will change the tuple. However, as you learned in Unit 5, tuples are immutable i.e. do not change. Therefore, to solve this problem, you need to find a way to change a tuple.

Answers

Answer:

The program is as follows:

my_tuple = (1,2,3,4,5)

print(my_tuple)

mylist = list(my_tuple)

mylist.append(6)

my_tuple = tuple(mylist)

print(my_tuple)

Explanation:

This defines a tuple of 5 integers

my_tuple = (1,2,3,4,5)

This prints the tuple

print(my_tuple)

To add new element to the tuple; First, we convert it to list. This is done below

mylist = list(my_tuple)

Then, an item is appended to the list

mylist.append(6)

The list is then converted to tuple

my_tuple = tuple(mylist)

This prints the tuple

print(my_tuple)

To lose weight, you must _______.

a.
increase exercise and increase caloric intake
b.
increase exercise and decrease caloric intake
c.
decrease exercise and increase caloric intake
d.
decrease exercise and decrease caloric intake

Answers

Answer:

B

Explanation:

because you need to exercise and eat or drink less calories

Answer: b. increase exercise and decrease caloric intake

Explanation:

What is the advantage of using shortcuts

Answers

Answer: There can be advantages and disadvantages.

for example, if you were in the woods with a pathway, and a clear way that might be faster and a shorter way of getting out. You may take the shortcut leading to where you didn't want to go leading to you getting lost or, it could be the same time but with more challenges.

An example of shortcuts to it's advantage is when you're reading a text and you don't understand the word. It's much easier when you hear it being read out to you when the reader uses tone to kind of give you a hint if the connotation is negative or positive, A good example of this is the word unique let's use this sentence "She was very unique, and that's what made her cool!" We can use the words "cool" to see that unique is a positive connotation! For the word cool can usually mean that something is real nice or it's something/someone you'd typically like to be around. So therefore these are just a few examples of the advantages and disadvantages of shortcuts.

Explain the three major Subassembly
of a computer Keyboard​

Answers

The keyboard is divided into four sections: alphabetical keys, function keys, cursor keys, and the numeric keypad.  Additional special-purpose keys perform specialized functions.  The mouse is a pointing device used to input data.  Input devices enable you to input data and commands into the computer.

The  three major Subassembly of a computer Keyboard​ are as follows;  alphabetical keys, function keys, and the numeric keypad.

What are the three major Subassembly of a computer Keyboard​?

The keyboard is divided into four components as; alphabetical keys, function keys, cursor keys, and the numeric keypad.

An Keyboard is an input Device used to enter characters and functions into the computer system by pressing buttons.

An Keyboard is a panel of keys that operate a computer or typewriter.

Additional special-purpose keys perform specialized functions.

The mouse is a pointing device used to input data.

The Input devices enable to input data and commands into the computer.

The  three major Subassembly of a computer Keyboard​ are as follows;  alphabetical keys, function keys, and the numeric keypad.

Learn more about the keybord here;

https://brainly.com/question/24921064

#SPJ2

Sarah is having a hard time finding a template for her advertising business that she may be able to use at a later
date and also make it available to her colleagues.
What is her best option?

Answers

Answer:

Making a custom template.

Answer:

Creating a custom template

Explanation:

Hope that helped.

In case of a suspected data breach, what course of action should a chief information security officer (CISO) take

Answers

Answer

1. Assemble his team

2. Find reason for breach

3. Evaluate what was lost

4. Ensure password change

Explanation:

In case of a suspected breach, the Chief information security officer should first of all assemble his incidence response team. This team should have representatives from all areas of the organization.

Then the reason for the breach and how access was gained has to be found out. An evaluation of what has been lost in the breach would be carried out and it's likely impact on the company.

In case credentials were stolen the CISO has to ensure that the employees change passwords. Also he has to notify all the necessary parties about the breach.

The CISO has to ensure that all employees are trained properly on security and they comply to security policies.

An alternative design for a canary mechanism place the NULL value just below the return address. What is the rationale for this design decision

Answers

Answer:

This is to prevent attacks using the strcpy() and other methods that would return while copying a null character.

Explanation:

Canary is a mechanism used to monitor and prevent buffer overflow. The alternative canary design that places a null value just before the return address is called the terminator canary.

Though the mechanism prevents string attacks, the drawback of the technique is that the value of the canary is known which makes it easy for attackers to overwrite the canary.

1. Discuss the pros and cons of human-computer interaction technology?
2. Discuss the ACID database properties in details ​

Answers

!

gcoo!!Exykgvyukhhytocfplanationufvhyg:

how would i change this:
" try:
userChoice = input("Would you like to Add or Multipy?(A/M): ")
except:
print("Please enter 'A' or 'M'") "

so it only allows me to put "A" or "M" so that it runs the except part

Answers

You wouldnt use a try and except statement. Use a loop.

how do I make my own algorithms ​

Answers

Answer:

Step 1: Determine the goal of the algorithm. ...

Step 2: Access historic and current data. ...

Step 3: Choose the right model(s) ...

Step 4: Fine tuning. ...

Step 5: Visualise your results. ...

Step 6: Running your algorithm continuously.

Get a basic understanding of the algorithm.
Find some different learning sources.
Break the algorithm into chunks.
Start with a simple example.
Validate with a trusted implementation.
Write up your process.

Fill in this function that takes three parameters, two Strings and an int. 4- // Write some test function calls here! The Strings are the message that should be printed. You should alternate printMessage("Hi", "Karel", 5); between the Strings after each line. The int represents the total number of lines that should be printed. public void printMessage(String lineOne, String lineTwo, in For example, if you were to call 19.
printMessage("Hi", "Karel", 5);
// Start here! 12 the function should produce the following output:
Hi
Karel
Hi
Kare

Answers

Answer:

The function in Java is as follows:

public static void printMessage(String lineOne, String lineTwo, int lines){

       for(int i = 1;i<=lines;i++){

           if(i%2 == 1){

               System.out.println(lineOne);

           }

           else{

               System.out.println(lineTwo);

           }

       }

   }

Explanation:

This defines the function

public static void printMessage(String lineOne, String lineTwo, int lines){

This iterates through the number of lines

       for(int i = 1;i<=lines;i++){

String lineOne is printed on odd lines i.e. 1,3,5....

      if(i%2 == 1){

               System.out.println(lineOne);

           }

String lineTwo is printed on even lines i.e. 2,4,6....

           else{

               System.out.println(lineTwo);

           }

       }

   }

To call the function from main, use:

printMessage("Hi", "Karel", 5);

Other Questions
Spiders only make one type of silk. True or false? Describe how the slave traders used fish to break the African men down mentally. Which of the following is not a benefit of being multicellular? Describe at least 2 examples of how the Industrial Revolution has impacted you to this day. Read the trailer for a movie about Prague in the Czech Republic. Prague is a medieval city of castles, courts, musicians, scientists, and the famous Charles Bridge. This great city experienced plagues, revolutions, and the invasion by Germany during World War II. A city known for the famous writer, Franz Kafka, Prague in Kafka's time (18831924) was shrouded in mystery, plotting, and intrigue. It faced dark days ahead: the German invasion. Which photo below best expresses the tone of the trailer? use trading in a sentence I will give 10 points! ??????????????????FAST HELP PLZ HELP!!!What is one reason why western Oklahoma has a different climate than eastern Oklahoma?a.There are large differences in the richness of soil between the western and eastern parts of the state.b.There are large differences in elevation between the western and eastern parts of the state.c.There are large differences in population between the western and eastern parts of the state.d.There are large differences in animal ecosystems between the western and eastern parts of the state.Please select the best answer from the choices providedABCD difference between mrna and dna In what direction is a line with an undefined slope going?A.down and to the rightB.horizontalC.verticalD.up and to the right URGENT!What propaganda techniques are used? ____ name calling ____ bandwagon____ glittering generalities ____ lesser of two evils____ pinpointing the enemy What inequality is represented by this graph? A. x > 6 B. x _< 6 C. x < 6 D. x _> 6 Simplify the expression a box of dried fruit has 51 calories in 3 servings. how many calories are in 1 serving? 2.is not considered aggressive driving.A. O SpeedingB. O Running stop signsC. O EatingD. O Tailgating 5-6(a) 1(b) -1(c) 11Select the correct answer !!!!!HELP OVER HERE!!!!!!!!! Calcium solid is placed in a solution of iron (III) chloride producing calcium chloride and iron solid PLSS HELP write the precent as a fraction or mixed number in simplest form (reduce) 36% What are some differences between the Britishand American colonists?