Question: Write a code for the following prompts. please write a runnable java code for the following You and a partner will create a program that

Write a code for the following prompts.

please write a runnable java code for the following

You and a partner will create a program that will compete against another program created by a pair of your fellow classmates in a game that generally follows the rules of Ghost. The game will consist of two programs that will take turns adding letters to a growing word fragment, trying not to be the one to complete a valid word. Each fragment must be the beginning of an actual word. The program that completes a word that has more than four characters loses. The program that creates a word fragment that has no possible chance of creating a word loses.

Programmatic Rules

Your program will compete against another program, the programs will communicate with each other by reading and writing from a shared file on the hard drive. Each program will take turns adding a letter to an ever-growing word fragment in the shared file. Before adding a letter to the file your program should figure out what the next best letter to play is. It should maintain the current word fragment and use methods in a class that extends AbstractDictionay.java to find the next letter to choose. There is a third program written by the professor, called the arbiter, that will officiate the game. The arbiter will also read and write to the shared file to communicate with the programs. The arbiter is responsible for starting and stopping the game as well as notifying each program when it is there turn. The arbiter will use a dictionary containing more than 100K words to decide if a word greater then four characters has been made or if a fragment has any possibility of creating a word. The arbiter will pass the file path of the shared file to your program as a Runtime argument. In your program's public static main(String[] args) function args parameter will be an array of length 1 and the first index will contain the file path to the shared file.

Conditions to Win

1) Your opponent creates a word

2) Your opponent creates a word fragment that has no chance of becoming a word

3) Your opponent takes more than 15 seconds to write their letter to the shared file

4) Your opponent writes text to the shared file that does not conform to the game Text Format Guidelines

5) Your opponent does not submit a program

Tip: If you are the first player you can only spell words that are odd length thus you can only lose when you spell words that are odd but you can win when your opponent spells words that are even length. Accordingly, if you are the first player you should only care about spelling even length words. You can tell if you are the first player by the length of the word fragment when it is your turn...

Text formate Guidelines

There are very simple rules that each program must follow when writing to the shared file. A program can only write to the share text file when it is their turn. And when they do write to the file they must follow the formatting pattern YOUR_FORMATED_TEAM_NAME+DELIMITER+(Your selected letter). Each line of text in the file will contain Keywords that can be used to figure out the state of the game and who's turn it is.

Key Words

GAME_START = "GAME_START"- denotes the game has begun

GAME_OVER = "GAME_OVER"- denotes the game is over

TURN = "TURN" - denotes a turn

DELIMITER = ":" - a value that separates values

YOUR_FORMATTED_TEAM_NAME = [Your team name] - your team name with all the white space removed and in all capital letters.

You will know when it is your turn when a line equal to YOUR_FORMATED_TEAM_NAME+DELIMITER+TURN is written to the file by the arbiter. You can only use standard American English ASCII alphabetical letters for your selection, no digits or punctuation marks. You need not worry about writing code for proper text formatting and parsing as it has already been done for you in the class TurnParser.java. This class contains methods that you can use to tell if it is your turn and to properly format your text. It is highly recommended that you used this class to parse and format your text as all the code has been written for you and it is well tested. Below you will find example text written to the shared file in a hypothetical game between "Team 1" and "Team 2":

Example Text File

GAME_START

TEAM1:TURN

TEAM1:T

TEAM2TURN

TEAM2:H

TEAM1TURN

TEAM1:E

TEAM2TURN

TEAM2:R

TEAM1:TURN

TEAM1:E

GAME_OVER

General Logic

First, your program should use a class that extends AbstractFileMonitor.java to monitor the shared file for changes and then use a class the extends AbstractDictionary.java to figure out the next letter to play. Your dictionary is expected to read from a dictionary text file of your choice that will accompany your program. Next, it should use the TurnParser.java to decipher the changes and to properly format text to write to the file. Lastly, it should use a class or classes that implement FileReader.java and FileWriter.java to read and write to the file.

Logic For Your AI If you are the first team you can only win if you attempt to create words with an even number of characters and if your the second team you can only win if you create words with an odd number of characters. Keep in mind the not all even/odd words will lead to victory as some of these words contain sub-words within them. So don't try to create words that have smaller winning words for your opponent. Always keep the system as simple as possible.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!