Question

In: Computer Science

Write a program in Matlab where the program plays a hot and cold game. The user...

Write a program in Matlab where the program plays a hot and cold game. The user answers two inputs: x=input('what is the x location of the object?') y=input('what is the y location of the object?') You write the program so that the computer plays the game. Pick a starting point. Program Calculates the distance to the object. Program picks another point, calculates the distance to the object. Program knows its at the right spot when the distance is less than 1. The program will consist of mostly loops and if-then statements. ONLY PROMPT THE USER TO INPUT THE "SECRET" X AND Y LOCATION. THE COMPUTER WILL FIND THE POINT. DO NOT KEEP PROMPTING THE USER TO KEEP GUESSING. IT IS THE PROGRAM'S JOB TO FIND THE POINT THE USER HAS CHOSEN. Program is finding a point the user picks in a 20X20 matrix. It also needs to have a counter built in so you know how many steps it takes the program to find the x,y coordinate. Points will be chosen using logic, not random.

Solutions

Expert Solution

The following information has been provided for the question above:

  • "Screen shot of Matlab code" for understanding of code indentation.
  • "Text format code" to copy and execute in your IDE.

NOTE: I used MATLAB R2017a IDE to execute this program code.

Screen shot of Matlab code:

Output:

Text format code:

%Computer will find the secret pick point by
%using20 x 20 matrix
computerSecretPickforX = randi([0 20], 1, 1)
computerSecretPickforY = randi([0 20], 1, 1)

%Prompt and read the input from the user
x=input('what is the x location of the object?')
y=input('what is the y location of the object?')

%Calculates the distance
calcDistance = sqrt((computerSecretPickforX - x).^2 + (computerSecretPickforY - y).^2);

% Verify the user guess input and computer pick is same or not
% If it is matched, then print the success prompt message,
% Otherwise using loop repeat the steps until the find the
% secret points
if x == computerSecretPickforX && y == computerSecretPickforY
    fprintf('Congrates! You got success')
else
    %While execute till condition is true.
    while true
        %Display message.
        fprintf("Not matched with computer secret point! Try again!\n")
       % Prompt the user to get x and y value.
        x=input('what is the x location of the object?')
        y=input('what is the y location of the object?')
        if x == computerSecretPickforX && y == computerSecretPickforY
          
            %Display message.
            fprintf('Congrates! You got success')
            break;
        end
        counter = sqrt((computerSecretPickforX - pointX)^2 + (computerSecretPickforY - pointY)^2);
        %Verify the secret point is very near match to
        %computer pick point then prompt the colder message,
        %otherwise prompt the hotter message
        if counter > calcDistance
            fprintf('Going colder...\n')
        else
            fprintf('Going hotter...\n')
        end
        calcDistance = counter;
    end
end


Related Solutions

1. Write a program that plays a simple dice game between the computer and the user....
1. Write a program that plays a simple dice game between the computer and the user. When the program runs, it asks the user to input an even number in the interval [2..12], the number of plays. Display a prompt and read the input into a variable called ‘plays’ using input validation. Your code must ensure that the input always ends up being valid, i.e. even and in [2..12]. 2. A loop then repeats for ‘plays’ iterations. Do the following...
Create a hot and cold game in Matlab to find a point in an (X,Y) 2D...
Create a hot and cold game in Matlab to find a point in an (X,Y) 2D coordinate plane. The user answers two inputs: x=Input('x') y=Input('y'). THE INPUTS WILL ONLY BE INTEGERS FROM 0 TO 100. This means no negative numbers. You write the program so the computer plays the game. The computer must play the game (comparing distances only) and give the same point as the user inputs. To keep it simple the code will check distances until distance =...
Java Project Requirements: 1.Write a Java program that plays a word game with a user. The...
Java Project Requirements: 1.Write a Java program that plays a word game with a user. The program asks the user questions and then creates a paragraph using the user’s answers. 2.The program must perform the following: a.Uses a Scanner object to ask the user: (The program asks for no other information) i.Full Name (First and Last name only) - stores this Full Name in one String object variable. ii.Age – must be read in as an int. iii.Profession or expected...
Write a program where a user of this program will play a game in which he/she...
Write a program where a user of this program will play a game in which he/she needs to guess a target number, which is a number that the program has randomly picked in the range that the user chooses. The program will repeatedly prompt for the guessed number and provide a clue whether the guessed number is bigger or smaller than the target number, until the guessed number equals the target number.
Write a Java program that lets the user play a game where they must guess a...
Write a Java program that lets the user play a game where they must guess a number between zero and one hundred (0-100). The program should generate a random number between 0 and 100 and then the user will try to guess the number. The program should help the user guess the number (see details below). The program must allow the user five attempts to guess the number. Further Instruction: (a) Declare a variable diff and assign to it the...
C Program and pseudocode for this problem. Write a C program that plays the game of...
C Program and pseudocode for this problem. Write a C program that plays the game of "Guess the number" as the following: Your program choose the number to be guessed by selecting an integer at random in the rang of 1 to 1000. The program then asks the use to guess the number. If the player's guess is incorrect, your program should loop until the player finally gets the number right. Your program keeps telling the player "Too High" or...
Program Created Last Week: #Program plays a guessing the number game with the user. #Importing random...
Program Created Last Week: #Program plays a guessing the number game with the user. #Importing random number with min number being 1 and max being 10 import random min_number = 1 max_number = 10 rand = random.randint(min_number, max_number) #Prints the header, welcoming the user print("Welcome to the Guess My Number Program!") while (True): #While loop, comparing the users guessed number with the random number. #If it matches, it will say you guessed it. guess = eval(input("Please try to guess my...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “Mahahanap mo na ang forever mo. Sana all!” If the user’s die is smaller, it should display, “Gising na friend,...
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB...
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB function should be voltage across the load (in Vrms, assume 0 phase), frequency Resistance of the load Inductance of the load power factor of the load target power factor The output of the function should be the size of the capacitor that one would need to place in parallel with the load to reach the target power factor. Please submit the code for the...
For this problem, you will write a program in which the computer plays a dice game...
For this problem, you will write a program in which the computer plays a dice game called Craps. You might need to explore some Python documentation on random() for this homework assignment. PROVIDE A GRAPHICAL FLOWCHART as part of your submission for this solution Rules: The player rolls two six-sided dice. After rolling, the sum of what the dice show is calculated. If the sum is 7 or 11 on the first roll, the player wins. If the sum is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT