# Predict Game

`PredictGame` is a part of a blockchain-based prediction game that leverages smart contracts for its operations. The contract is designed for a game where players predict whether a certain asset's price will go up or down within a specified time frame.

## Imports and Dependencies

* **OpenZeppelin's Ownable.sol**: Ensures that certain functionalities are restricted to the contract owner.
* **Predict.sol**: A contract that manages prediction logic or game settings.
* **DataFeed.sol**: Interface to an external data feed, for fetching real-world asset prices.
* **PredictBet.sol**: Represents an individual bet within the game.

## Main Components

* **DataFeed**: A reference to a data feed contract that provides the asset prices.
* **Predict**: A contract that manages the core functionalities of the prediction game.
* **interval**: The time interval between prediction rounds.
* **bonus**: An additional reward percentage for winning bets.
* **symbol**: Symbol of the asset being predicted on.
* **active**: A flag to activate or deactivate the game.
* **lastCalculatedRound**: Keeps track of the last round that was calculated.
* **duration**: How long a prediction round lasts in count of intervals.
* **threshold**: Maximum allowed time difference for fetching the end data of a round.

## Events

* **`BetCreated`**: Emitted when a new bet is created.
* **`RoundCreated`**: Emitted when a new prediction round is created.
* **`RoundCalculated`**: Emitted when a round's results are calculated.

## Key Functions

### Constructor

Initializes the contract with necessary parameters like the data feed address, asset symbol, game interval, bonus percentage, round duration, and threshold.

### `getCurrentRound`

Calculates the current round based on the current timestamp and the interval.

### `placeBet`

Allows placing a bet on the prediction of the asset's price movement. It creates a new `PredictBet` contract for each bet and updates the pools and bets arrays accordingly.

### `calculateBets`

Calculates the result of bets for a specified round. It ensures the round has finished, fetches the start and end prices, and then determines whether long or short bets won. It also handles the case where the result is a draw.

### Helper Functions

* **`calculateDrawResult`**, **`calculateLongResult`**, **`calculateShortResult`**: Determine the outcome of the bets based on the price movement and distribute rewards accordingly.
* **`activate`**, **`deactivate`**: Functions to activate or deactivate the game.

## Usage

To create this contract, the [Predict](/smartcontracts-description/predict-contract.md) contract initializes it with the necessary parameters. Players can then place bets on asset price movements. After each round, the contract calculates the outcomes and distributes winnings based on the asset's price changes.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.celestium.digital/smartcontracts-description/predict-contract/predict-game.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
