1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
serg [7]
3 years ago
9

In this lab, you will develop a game, "Tic Tac Toe". Assume there are two players; the computer and theuser.Initially you will

create the board, a 3x3 matrix, and fill it out with zeros.Ask user to start first, and record the user’s input as 1You can ask the user to enter the row first than the column (for ex; the user can enter 2 and 1,then the code shouldupdate the value of second row first column)The computer should make random moves, and the computer input should be recorded as 2After each move, check if someone wins, and display the boardDisplay the result (who wins and the board)Create as much helper functions as needed.Divide and ConquerSampleRun:board = [[0,0, 0],[0,0, 0],[0,0,0]]enter the row;2enter the column;1board = [[0,0, 0],[1,0, 0],[0,0,0]]the computer playsboard = [[0,2, 0],[1,0,0],[0,0,0]]CS103-Lab9Page4of6enter the row;2enter the column;2board = [[0,2, 0],[1,1, 0],[0,0,0]]the computer playsboard = [[0,2, 0],[1,1, 0],[0,0,2]]enter the row;2enter the column;3board = [[0,2, 0],[1,1,1],[0,0,2]]Game Over !!!!Winner: The User

Computers and Technology
1 answer:
Aleonysh [2.5K]3 years ago
4 0

Answer:

Code:

# importing all necessary libraries

import numpy as np

import random

# Select a random place for the player

def play(board, player):

selection = availableSpots(board)

if player==1:

row=(int)(input("Enter the row :"))

column=(int)(input("Enter the column :"))

current_loc=(row-1,column-1)

while current_loc not in selection:

print("Invalid Input. Please give again")

row=(int)(input("Enter the row :"))

column=(int)(input("Enter the column :"))

current_loc=(row-1,column-1)

else:

current_loc = random.choice(selection)

board[current_loc] = player

return board

# Check for empty places on board

def availableSpots(board):

  l = []

  for i in range(len(board)):

      for j in range(len(board)):

          if board[i][j] == 0:

              l.append((i, j))

  return(l)

# Creates an empty board

def create_board():

  return(np.array([[0, 0, 0],

                  [0, 0, 0],

                  [0, 0, 0]]))

# Checks whether the player has three

# of their marks in a horizontal row

def row_win(board, player):

  for x in range(len(board)):

      win = True

      for y in range(len(board)):

          if board[x, y] != player:

              win = False

              continue

      if win == True:

          return(win)

  return(win)

# Checks whether the player has three

# of their marks in a vertical row

def col_win(board, player):

  for x in range(len(board)):

      win = True

      for y in range(len(board)):

          if board[y][x] != player:

              win = False

              continue

      if win == True:

          return(win)

  return(win)

# Checks whether the player has three

# of their marks in a diagonal row

def diag_win(board, player):

  win = True

  for x in range(len(board)):

      if board[x, x] != player:

          win = False

  return(win)

# Evaluates whether there is

# a winner or a tie

def evaluate(board):

  winner = 0

  for player in [1, 2]:

      if (row_win(board, player) or

          col_win(board,player) or

          diag_win(board,player)):

          winner = player

  if np.all(board != 0) and winner == 0:

      winner = -1

  return winner

def printWinner(winner):

print("Game Over !!!")

if winner==1:

print("Player Wins")

elif winner==2:

print("Computer Wins")

else:

print("Nobody Wins")

# Main function to start the game

def play_game():

board, winner = create_board(), 0

print(board)

while winner == 0:

for player in [1, 2]:

board = play(board, player)

print("Board")

print(board)

winner = evaluate(board)

if winner != 0:

break

printWinner(winner)

play_game()

Explanation:

See screen shot of code and see final output

You might be interested in
How do i add a header or footer to powerpoint presentation
BartSMP [9]
When you have you presentation open, go to Insert > Header & Footer.

7 0
4 years ago
In the context of intentional security threats, _____ can erase data and wreak havoc on computers and networks but do not replic
mihalych1998 [28]

Answer:

The answer is "Option D".

Explanation:

Trojan program is a malicious code that is also known as a virus. It is a rootkit, that aims to infect the computer to hide or obscure an object. These programs are mainly used to download additional content, such as additional pieces of malware, to the infected computer, and other options are wrong that can be defined as follows:

  • In option A, It is not correct, this option infects the system.
  • In option B, It is used for infects another computer that's why it is incorrect.
  • In option C, It is incorrect because it is used in cybersecurity.  
5 0
3 years ago
Which of the following is Tynker an example of?
dangina [55]

Answer:

binary code

Explanation:

correct me if i’m wrong :)

6 0
3 years ago
Read 2 more answers
An Agile Team decides they want to use pair programming in future Iterations. Where should this be captured? g
Umnica [9.8K]

Answer:

The decision to use pair programming by an Agile Team should be captured in their <em>Inspect and Adapt meeting notes.   </em>

Explanation: The underlying principle for having an agile team that the team is committed to constant incremental and or progressive improvement.

Inspect and Adapt Meeting Notes are notes which hold the summary of past achievements which hold and records of things to do going forward in order to ensure that there is progress and improvement over the last set of objectives.

These notes are usually taken at the Inspect and Adapt meeting. This is simply a meeting held at the end of each project milestone. An agile team during this meeting will review its performance, agree and document how it can be more effective.

Pair programming is also an Agile practice in the parlance of software development. Instead of the regular method where an individual is tasked with the development of an application, in this case, two programmers are tasked with the development of one App.

Sometimes this method is used during Extreme Programming (XP)

Cheers!

7 0
3 years ago
Today, there are many computer categories. A(n) ________ is the category for the world's fastest computers. ________ computers a
Musya8 [376]

Answer:

Supercomputer

Mainframe

Servers

Desktop

Laptop

Mac

iOS

Windows

Android

Explanation:

Speed is salient characteristic of supercomputers. The Mainframe computers are usually used by large companies and are very expensive with large processing capability. Servers enables thw possibility of establishing connections with service providers such as Google and other related companies. Desktop computers are those which aren't designed for portability or being easily carried around. The Laptops on the other hand are more compact and easily carried around. Mac are operating systems associated with Apple computers and iOS is the operating system used on iPhones and other Apple smart mobile devices. Windows is the me of the operating system used by Microsoft. Android is also a popular operating system used on smartphones.

3 0
3 years ago
Other questions:
  • How can i put this sign in my keybord?<br><br> :::::<br> ^<br> Here is the sign
    8·1 answer
  • 40 POINTS I NEED THESE ANSWERS ASAP GIVE ME THE RIGHT ASNWER AND ILL PUT YOU AS THE BRAINLIEST
    13·1 answer
  • Climate is considered a(n) _______ limiting factor. (2 points)
    9·1 answer
  • Tom is required to present the activities of his Nature club each month to the school committee. Which presentation element can
    12·2 answers
  • How can you create the first row of the table as the header of the table?
    8·1 answer
  • Which term is used to describe bitmap images
    8·2 answers
  • Computer-generated random numbers are normally distributed. true or false
    11·1 answer
  • Pls help me with this pls
    7·2 answers
  • Why is it important to prevent financial loss
    7·1 answer
  • When we connect to a story, it can be mental, emotional, or even physical. <br> True or False?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!