A browser-based Hit and Blow game where the player competes against the computer.
- The player selects 3 (or 4) distinct numbers from 0 to 9 and decides their order.
- The roles of the first and second player are determined.
- The first player makes a guess of the opponent's numbers and declares it.
- The opponent responds with the number of "hits" (correct number and correct position) and "blows" (correct number but incorrect position).
- Then, the second player makes a guess of the first player's numbers and declares it.
- Similarly, the first player responds with the number of "hits" and "blows."
- Repeat steps 3 to 6, and the first player to correctly guess all the numbers in the correct order wins the game.
- A "hit" occurs when both the number and position are correct.
- A "blow" occurs when the number is correct, but the position is incorrect.
- Duplicate numbers are not allowed when deciding one's own numbers.
- プレイヤーは異なる数字で0~9のうちから3つ(または4つ)を選び、その順番も決定します。
- 先攻・後攻を決めます。
- 先攻が相手の数字を予想し、それを宣言します。
- 相手はその予想に対して「hit」(数字と位置が合っている)および「blow」(数字は合っているが位置が異なる)の数を答えます。
- 次に、後攻が相手の数字を予想して宣言します。
- これも同様に、先攻が「hit」と「blow」の数を答えます。
- 3~6の手順を繰り返し、最初にすべての数字と順番が一致したプレイヤーが勝利します。
- hitは数字および順番が正しい場合
- blowは数字は正しいが順番が誤っている場合
- 自分の数字を決める際、重複する数字は使えない
The game start screen is created using Next.js. The start screen includes a title and a start button that navigates to the game page.
To run the Next.js application, follow these steps:
-
Build the Docker image:
docker-compose build -
Run the Docker containers:
docker-compose up -
Open http://localhost:3000 with your browser to see the result.
To run the FastAPI backend server, follow these steps:
-
Build the Docker image:
docker-compose build -
Run the Docker containers:
docker-compose up -
The server will be available at http://localhost:8000.
The /start-game API returns the following JSON response:
{
"computer_numbers": [1, 2, 3],
"game_id": "unique-game-id",
"timestamp": "2023-01-01T00:00:00"
}computer_numbers: An array of distinct numbers selected by the computer in a random order.game_id: A unique identifier for the game session.timestamp: The timestamp when the game was started.
The FastAPI backend server uses Python's built-in logging module to log game start requests. To configure the logging settings, follow these steps:
- Open the
backend/main.pyfile. - Locate the logging configuration section:
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
- Modify the logging level, format, or other settings as needed.
To set up the local development environment for running both the Next.js application and the FastAPI backend server, follow these steps:
-
Clone the repository:
git clone https://github.com/kaoru0310/hit-and-blow.git -
Navigate to the project directory:
cd hit-and-blow -
Build the Docker images:
docker-compose build -
Run the Docker containers:
docker-compose up -
Open http://localhost:3000 with your browser to see the Next.js application.
-
The FastAPI backend server will be available at http://localhost:8000.