98.0k views
4 votes
Design and code an Omok application that

takes all user inputs from the standard input (System.in) and displays
all outputs to the standard output (System.out).
Omok (a.k.a. Gomoku and Gobang), literally meaning five pieces, is a
two-player strategy game typically played with go pieces --- black and
white stones --- on a go board with 15x15 intersections (or places)
[Wikipedia]. It is also possible to play the game with paper and
pencils because stones, once placed, can't be moved or removed from
the board. The two players alternate and place a stone of their color
on an empty intersection. The game objective is to put one's stones in
a row of five consecutive places vertically, horizontally, or
diagonally. The winner is the first player to create an unbroken row
of five stones.
Your application shall meet the following requirements.
R1. The application shall take all user inputs from the standard input
(System.in) and display all output to the standard output
(System.out).
R2. The application shall provide two different game modes: human game
and strategy game. In the first game mode, two human players play
against each other, and in the second, a human player plays
against the computer. Your application shall provide a realistic
or reasonable playing strategy for the computer. Minimally, it
should detect a winning/losing row, e.g., four consecutive stones
with an open end.
R3. The game board shall consist of n*n intersections (or places) on
which stones of the players are placed, where n >= 15.
R4. The application shall provide a way for the user to select the
game mode (see R2 above).
R5. The application shall provide a way for the user to place his or
her stone in an empty intersection (or place) of the board.
R6. The application shall show the progress of a game by displaying
the current configuration of the board -- all the stones placed --
along with other status information, e.g., a player's turn.
Consider using an ASCII drawing to show the board configuration.
R7. When the game ends, the application shall display the outcome of
the game --- a win or draw --- and highlight the winning row.
R8. The application shall provide a way to quit the game, e.g., by
entering a special input value.
R9. You shall separate your user interface (UI) code from the model
code that performs the game logic. The model code should not
depend on the UI code. We suggest you create a separate class for
the UI, say ConsoleUI, and make the model code independent of the
UI class. That is, the UI code may depend on the model code, but
not the other way around. Note you will reuse your model code in
later assignments but not the UI code.
1. Code your design by naming your main (or entry point)
class as Main.
2. (Bonus: 10+ points) Implement a "cheat" mode and provide a way to
enable and disable it --- e.g., entering a special value when
prompted for the next move. In the cheat mode, the application
suggests the next move for the user. It should minimally detect a
winning or losing sequence, e.g., a row of four consecutive stones
with an open end.
TESTING
Your code should compile and run correctly with Java 10 or later
versions.

User Basteln
by
7.5k points

1 Answer

3 votes

Final Answer:

To create an Omok application in Java that meets the specified requirements, you can follow the object-oriented programming principles by separating the user interface (UI) code from the model code. Create a main class named `Main` to serve as the entry point. Implement two game modes: human vs. human and human vs. computer with a reasonable computer strategy. Ensure the game board is at least 15x15, and allow users to input their moves via standard input. Display the board's progress and game outcome in the standard output. Lastly, implement a cheat mode for users to enable/disable, suggesting next moves based on potential winning or losing sequences.

Step-by-step explanation:

The design follows a modular structure, with a `Main` class as the entry point. This adheres to the separation of concerns, where the UI and game logic are distinct, promoting code reusability. The two game modes offer variety for users, and the computer strategy in the second mode enhances the application's challenge. The game board's minimum size of 15x15 ensures a standard Omok experience.

User interactions occur through standard input and output, providing a streamlined experience. The display of the board's progress with ASCII art facilitates easy understanding of the game state. The application checks for a winning or draw outcome, highlighting the winning row when applicable.

The bonus "cheat" mode enhances user engagement. Enabling users to receive hints based on potential winning or losing sequences adds an extra layer of strategy. This feature provides users with an opportunity to learn and improve their gameplay, making the application more interactive and enjoyable.

User Thibault Ketterer
by
7.6k points