代做CSCI 201, Fall 2024, Assignment 2 Implementation Recommendations调试Java编程

CSCI 201, Fall 2024, Assignment 2

Implementation Recommendations

A server-client crossword game application is implemented in this assignment with certain requirements on game play logics and UI display. This document will primarily focus on the  high-level  interpretation  to  achieve  the  crossword  game  functionalities  detailed described  in  the  assignment  instruction  “Assignment2.pdf” .  The  key  points  will  be emphasized,  and  the   implementation  recommendations  are  provided  for   potential inspirations.

Outline

Part 1: The general overview

1.1      Resource Management

1.2      Process Management

Part 2: The class design

2.1      Server class

2.2      Client class

Part 1: The general overview

1.1. Resource Management

1.1.1  All game files (.csv) are placed in gamedata/ folder under current project directory. The program should be able to

1)  scan all .csv files in gamedata/,

2)  check if a randomly selected file is valid, and

3)  store the word entries (across/down-index-question-answer) properly.

1.1.2  A game data object needs

1)  to contain word entries properly,

2)  to  be  updated once a client answers an entry correctly (or to record client answers),

3)  to be visually generated, and then displayed in console.

1.1.3  All server resources are shared with limited number of clients (Number of client lines need to exactly match the number provided by Player 1)

1)  The game will not start if the clients are less than this number.

2)  No more players can join the game if this number is reached.

1.2. Process Management

1.2.1  Server-client communication

1)  One  server  communicates with  multiple clients  independently.  It  sends the updated game status to all clients, receive the response from all clients, and sync other clients with the message received from certain clients.

2)  There  is  no  direct  communication  between  any  two  of  the  clients.  They communicate with intermedia assistance of the server.

3)  The main functionality of client ends is sending players type-ins and displaying the server messages. It is optional for the client end to record the player’s game

info (e.g. number of correct answers the player guesses).

1.2.2   Multi-thread concurrency

1)  The clients are independent with each other.

a.  Players’ reactions in the clients do not interrupt other client lines.

b.  After the game starts, when one player (active player) is communicating the server, all other clients need to wait for the active player to finish the communication.

2)  The   process  of  game  preparation  is  independent  from  the  process  of connecting other clients (if there is supposed to be any). The game preparation includes valid game file selection, game file info storage, and game board generation.

Part 2: The class design

Based on the above analysis on resource management and process management, one optional structure design for Server class and Client class can be:

2.1   Server Class

2.1.1   Game board management

In this part, students

1)  Can consider to use java.io.File to read game file list in a certain directory. Can also consider java.io.FilenameFilter for file name filtering.

2)  Need to randomly select a game file with the usage of java.util.Random.

3)  Can   consider   to   parse   the   selected   .csv   file   by java.util.Scanner or java.io.FileReader

(more  info can  be found: https://piazza.com/class/ly551p113od3l9/post/121) Organize  the  entry  info  in  .csv  file  (question  direction,  index,  description, answer) and use a proper data structure to store it (e.g. Map, List, etc.)

Step -2) and 3) should be repeated until the game file satisfies the requirements (check “Assignment.pdf” for details). Once a valid game file is found, parsed, and stored properly,

4)  Generate the visual game board by spatially placing all word entries into the board.

To represent the game board, it is very flexible to choose any proper 2-D data structure.   ArrayList>,    Vector>,   char[][], String[][], or any other structures that can satisfy the storage and afterwards printing and also updating/modifying requirements are okay to use. Choose a data structure based on your own dataflow design.

Then,  to  organize  the  2-D  spatial  positions  of  the  words,  here  are  many possible solutions to achieve this goal. One possible solution can be:

•   Sort all the words by decreasing length,

•    If there are words unplaced in game board,

o Pick the next unplaced word w_unp according to the sorting order

o Check if there is any placed word w_pl_idx in the other direction sharing the same index, if yes:

Place the word w_unpl starting from the head position of word w_pl_idx,

o else, start to check intersections in decreasing-length order with the previous placed words in the other direction (called reference words)

for  a   certain   reference   word w_pl,   the   intersection checking of word w_pl and word w_unpl can be conducted by a letter-wise examination from the end of the words to the beginning* (a double for loop involved).

o If the unplaced word w_unp cannot find its intersected word in other direction (either intersection common letter does not exist, or the intersection position is not available), it will be pushed to the end of the unplaced word array, waiting for another trial when there are more words in the board **.

* The example algorithm for intersection checking examines the possible intersection letter from the word end to word beginning, mainly to yield the priority of the FIRST letter of word w_unpl for possible intersection with other unplaced word in the future.

** Current strategy is aiming at making all words to overlap as much as possible. There are many other choices to deal with the case where word w_unpl fails to find a position ensuring intersection(s) with placed words. For example, word w_unpl can be temperately placed with certain cells away from the placed words, or try to look for other positions for the word placed in current intersection position which is also suitable for word w_unpl (intersection position for a certain word can be more than one).

Some randomness can even be introduced, e.g. in selecting word to place or in searching for placed words for intersection, to reduce the possibility of getting stuck in placing new words. Students are well welcome to look for other crossword entry-to-board algorithms.

5)  Display  the  game  board  in  console  when  needed.  The  display  is  slightly different from the game board storage. There are three possible statuses of a cell in a game board, empty (i.e. no letter involved), covered (i.e. not correctly guessed), and released (i.e. corrected guessed), and they should be displayed by space(s), underline(s), and the letter itself (possibly with spaces for ensure the commonly shared cell length), respectively. The status of empty cells will not be modified at all, while only the covered cells will be updated to released cells in valid updating. Besides, some cells shared by two words as the FIRST letter, the word  index  remains  after  the  first-time  release.  Please  refer  to “Assignment2.pdf” for more display details.

Additionally, the cell length in console display should be the same regardless of the cell status to provide the meaningful display. We don’t want the letters in the Down words to shift in a zig-zag pattern. One possible solution is to store each row of the game board in an ArrayList, then call Arrays.toString() to generate the  corresponding  string,  and  don’t  forget to  replace  left  square bracket (“[”), comma (“,”), and right square bracket (”]”) transformed from the ArrayList in the string with space (“ ”) for visual pleasure.

This whole part related to game board management handled by the server is relatively independent from the other functionalities. Moreover, 2.1.1-1) to 2.1.1-3) should be conducted simultaneously when the server waits or connects with other Players (if any) besides Player 1. Therefore, it is recommended to create a Game class extended from Thread, and put 2.1.1-1) to 2.1.1-3) in its run() method.

2.1.1-4) game board generation is more about organizing spatial positions of the word  entries  in  a  2-D  array.  This  step  is  one-time  needed.  Once  the  spatial structure is settled, it is the status of cells that need to be updated and displayed appropriately during game time (2.1.1-6).

2.1.2 General game status tracking and turns determination

Once the game starts, the server also needs to track the general game conditions, including

•   The words that are not correctly guessed, i.e. available questions for next turn

The number of correct guesses for each player, i.e. score counting

•   Current turn and the evaluation of the current guess, and afterwards next turn determination

2.1.3 Communication with clients

Please carefully digest the related lectures and the corresponding example codes. Key   lectures    and   codes:    (reference   lecture    slides:   NetworkingCode.pdf, NetworkingCode-Multithreaded.pdf)

→ Networking with multiple clients:

•    Networking  with   multiple  clients:  Use ServerSocket() to  manage  the networking. Use Socket() to manage the connection to a client.

•   Create ServerThread() to manage the client-wise communication.

2.1.4 Synchronization control

1) ServerThread.run() method should be adaptive to the player activation status, as the waiting player(s) can only receive the sync messages after the active player finishs the interaction with the server. Besides, the waiting behavior. can be managed by a lock.

2)  The number of players that can simultaneously connected to the server can be controlled by Semaphores() in server for ServerThread() instances.

2.1.5 Termination

Once starts, the server will not stop unless be manually terminated. This feature can be achieved by an infinite while loop.

2.2   Client Class

2.2.1 Client thread communicate with the server

2.2.2 Termination

Once the game concludes and the clients received the results, the clients will automatically terminate. “ System.exit(0);” can be used for program termination.

2.2.3 Synchronization (optional)

Synchronization in the clients is generally not needed. The 2 key points in the rubric on synchronization are on the common synchronization control for server and clients. Please have your own synchronization control design based on need. If your implementation works correctly without client synchronization, it will receive full points.


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图