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 =...
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...
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...
(Using Matlab) and "while" function 1.   Write a program that prompts the User for if they...
(Using Matlab) and "while" function 1.   Write a program that prompts the User for if they would like to enter a real number. If yes, prompt the User for the real number. Continue to do this until the User enters “no” to the first question. After the User enters “no”, display the average of all the numbers entered. (Using Matlab) and "while" function 2.   Write a program that prompts the User for if they would like to enter a real...
11. Write a user oriented MATLAB program that will calculate the capacitance of the capacitor connected...
11. Write a user oriented MATLAB program that will calculate the capacitance of the capacitor connected across the loads to improve the overall power factor to 0.8 lagging,0.9 lagging, unity power factor, 0.8 leading, 0.9 leading. Also MATLAB will calculate total reactive, real power, and the total current at the source for each ste
MATLAB Write a script which asks the user of the program to provide an initial horizontal...
MATLAB Write a script which asks the user of the program to provide an initial horizontal position, initial vertical position, initial velocity, and angle. Create a time vector spanning from zero seconds to 100 seconds incremented at 0.01 seconds. Call the function that you created in the previous problem to calculate the trajectory and velocities of the projectile. Find the maximum height of the projectile and the time at which it reaches that point. Write a neat sentence stating what...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT