Do not program a GUI - your application should be text-based. Basic Game I: Computer chooses, Player guesses The computer starts by randomly choosing a 4-letter word over the 4-letter alphabet {A,...

1 answer below »

Do not program a GUI - your application should be text-based.



Basic Game I: Computer chooses, Player guesses



The computer starts by randomly choosing a 4-letter word over the 4-letter alphabet {A, B, C, D}, e.g. ACBD. The player then starts to guess the computer’s choice, e.g. the player could guess AACA. The computer compares the user’s guess with its choice and outputs a word over the alphabet {<, =,="">} that contains:



for each correctly guessed letter an equals symbol =



for each letter that is too small a less-than symbol



for each letter that is too big a bigger-than symbol >



Note that the order of the letters in the output word does not matter! In the given example a possible output could be <=> because two guessed letters are too small, one is correct and one is too big (the third guessed letter is C compared with letter B in the computer’s choice).



If the player guessed correctly, the game ends by congratulating the player. Otherwise a new round of the game begins, i.e., the user is asked to enter another guess. If the player does not guess the right letter combination after 6 rounds the player loses and the game terminates.



Basic Game II: Player chooses, Computer guesses



This game is the same game as the previous one but with switched roles. First, the player is asked to choose a combination of a 4-letter word over the 4-letter alphabet {A, B, C, D} (that she/he can write e.g. on a piece of paper.) The computer then starts guessing a combination and the player has to enter a word over the alphabet {<,=,>} that correctly evaluates the computer’s guess. For example, if the player chose the word AAAA and the computer guessed CCAC the player has to enter the word >>>=. The order of the symbols in the player’s word should not matter, so he could have also entered the word >=>> or =>>>.



Again the game proceeds in rounds as described previously - if the computer manages to guess the right combination, it wins. If this does not happen after 6 rounds, it loses. In order to minimise the likelihood that the player cheats by changing his original choice during the game, the program should maintain a list of possible combinations that is updated after each guess. For example if the computer guessed AAAA and received the reply



In case the list of possible combinations becomes empty during a game, the game should terminate and inform the player that the computer suspects that the player was either cheating or evaluating one of the computer’s guesses wrongly.



The computer should follow a “reasonable” strategy when trying to guess the combination. The most basic requirement for such a strategy is to choose only from those combinations that are still possible (given the history of the game). For the purpose of this exercise it is sufficient to implement this basic strategy, but you could try to improve the strategy of the computer if you wish to.



In both game options the computer should display at the beginning of each round the number of rounds played and the remaining number of possible combinations.



Please add the following features:


As a player I want to be able to get a hint for a letter, so I can solve the game faster.


As a player I want to be able to save a game so I can play it at another time.


As a player I want to be able to load a game so I can continue a game I was previously


Playing.


As a player I want to be able to show the solution so I can see the answer to a game I can’t


solve.


As a player I want to store my player name so the software can track my game play statistics.


As a player I want to load my details so I can track my game play statistics.


As a player I want the software to track the number of games I have played.


As a player I want the software to track the number of correct guesses I have made so I can see


how accurate I am as a percentage of my total number of guesses


As a player I want to be able to see the top 10 scores for number of successfully completed


games( top score would be the user completes the game in the least attempts).





Answered 1 days AfterJul 31, 2021

Answer To: Do not program a GUI - your application should be text-based. Basic Game I: Computer chooses,...

Arun Shankar answered on Aug 01 2021
155 Votes
// Basic Game 1
import java.util.Random;
import java.util.Scanner;
import java.io.FileWriter;
import java.util.ArrayList;
import java.io.File;
import java.io.FileNotF
oundException;
import java.io.IOException;
class Main
{
// Generate ther 4 letter word over
// {A, B, C, D}
public static String generate_word()
{
String s = "";
char[] alphabet = {'A', 'B', 'C', 'D'};
Random rand = new Random();
for(int i = 0; i < 4; i++)
{
int index = rand.nextInt(4);
s = s + alphabet[index];
}
return s;
}
public static void print_symbols(String computer_word, String user_guess)
{
if(user_guess.length() != 4)
System.out.println("The string is 4 letters long!");
else
{
for(int i = 0; i < 4; i++)
{
char a = computer_word.charAt(i);
char b = user_guess.charAt(i);
if(a == b)
System.out.print("=");
else if(a < b)
System.out.print(">");
else
System.out.print("<");
}
System.out.println("");
}
}
public static void print_instructions()
{
System.out.println("--------------------------");
System.out.println("Type HINT to see a hint");
System.out.println("Type STATS to view statistics");
System.out.println("Type SOLVE to view the answer");
System.out.println("Type your four letter guess");
System.out.println("Type MYSTATS to view my statistics");
System.out.println("--------------------------");
}
public static void populate_history(ArrayList arrlist)
{
try
{
File f = new File("scores.txt");
Scanner s = new Scanner(f);
while...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here