Introduction

In this project we will implement an interactive game server running on the Internet.

And will include a server side and a client side with a graphical interface.

The entire project will be written in the Java language.

The server will have several game options and will allow you to play several games simultaneously, on the same computer or from a number of different computers.

We will play two games: "Tic Tac Toe" and "Catch the Bunny".

Both games are designed for a single player against the computer.

Our server will be built so you can easily add more games if we wanted to.

The Project Classes are located in this document, and do not modify signatures of functions.

The definitions and interfaces should be same as in the API.

Part A

In this section we will implement the two games and the logic of each of them.

Rules of the game TicTacToe

  • The game takes place on a 3 by 3 board for 2 players.
  • At the beginning of the game each player is assigned an X - or - round mark.
  • The course of the game: Each player in turn selects an empty slot on the board (which does not contain a sign) and places its mark on it.
  • A winner in the game of the player who succeeded in creating the first sequence of three symbols (X or circle), which are on one row, one column or one diagonal.
  • If the board fills up and no sequence is created, the game ends in a draw.

Rules of the game Catch the Bunny

  • The game takes place on a 9 by 9 board.
  • There are 2 players: Boy and Bunny.
  • Each character is in a certain position on the board.
  • In each turn, one of the characters is moving by 1 slot.
  • The game ends when the Child catches the Bunny, that is, moves to the square where the Bunny is, or when the Child did X steps (X is the number of allowed steps given in the start of the game) and then the Bunny wins. Each character can move one square in four possible directions: up, down, right or left.
  • The selected direction in which the child moves will be determined by the user, Right = D, Left = A, Bottom = S, Top = W.
  • The direction in which the Bunny moves will be determined by the computer.

Rules for the joint realization of both games

  • The choice of the computer's move will have two modes: a logical choice and a random selection.
  • The type of selection will be determined when the object of the game is initialized.
  • In both games, when the computer is on a random selection mode, the computer will randomize a step (legal of course) and it will be the chosen step.
  • When computer is on the logical selection mode, the computer must calculate which selection will increase his chances of winning the game. When implementing this case, please define the selection algorithms yourself in order to realize the algorithms, one or more of the existing data structures in the (collections) can be used.

As mentioned in the introduction, we want to implement the server so that more games can be easily added.

In order to fulfill this requirement, we will use the "Strategy Pattern" method: we will define an interface through which the games can be played. A department that will manage a game will maintain a reference to this interface and use it, but will not recognize his various implements (the actual realizing classes, which are called Concrete Classes).

The departments that will realize both games will realize this by implementing the interface (they will contain functionality similar, with the same usage).

Also, this will allow us to easily hold one game by choice and replace when needed.

Interface that we define will be called IgameAlgo, and it will contain the following methods, which will allow to manage the game from start to finish:

  • The first method that the interface defines is getGameState, which helping the reader to know the state of the game, display it when necessary or decide to continue or end the game. Finish a game happens when one of the following conditions occurs: win / loss / draw.
  • Next method to be set is updatePlayerMove, which will update one step of the player in the game, as long as it is legal.
  • The last method is calcComputerMove it decides what step the computer will make in the game when it's his turn. In the classes that implement this interface, this method will actually define the algorithms mentioned above. For each game, there will be an implementation that will decide on a step in a random way, while maintaining the rules of the game, and the implementation of one who will decide on a step in logical manner which will increase computer's chances of winning the game.

The above interface will be implemented as an abstract class called GAMEBoard. It serves as a common denominator between all games available in the software.

For each game, we define an abstract class: CatchTheBunny and TicTacTow. These classes will implement the Tic Tac Toe and Catch the Bunny respectively.

They will implement all the methods defined in the interface IgameAlgo Except for the method calcComputerMove.

For each of the classes CatchTheBunny and TicTacTow we will define two classes that inherit from them, which will each perform the method calcComputerMove according to the chosen algorithm.

Classes CatchTheBunnyRandom and TicTacTowGameRandom will implant random selection in the Tic-Tac-Toe game and Catch the Bunny, respectively, as described above.

The classes CatchTheBunnySmart and TicTacTowGameSmart will implant an logical choice in Tic-Tac-Toe and Catch the Bunny, respectively, as described above.

Note, that in these classes, since the algorithm definition is part of the task, it is highly recommended to document the code so that whoever reads it can understand what you mean.

The last two Classes that we will implement in this section are test departments.

There is great value for unit testing during the development process, even before that we are interfacing with another part of the software or handing over the software.

Implement two classes with the help of Junit framework: CatchTheBunnyTest and TicTacTowTest

Each class will check the two algorithms of its game and will contain a method @test for each of the computer game algorithms.

Finally, pack all 10 Classes described in packages In the structure (pay attention to the structure of the folders) and the following names: see image.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.