# Tournament

## Creating a Tournament

## Create Tournament

<mark style="color:green;">`POST`</mark> `[endpoint]/v3/tournament/create`

#### Query Parameters

| Name                                                 | Type     | Description                                           |
| ---------------------------------------------------- | -------- | ----------------------------------------------------- |
| game\_id<mark style="color:red;">\*</mark>           | String   | Game ID                                               |
| tournament\_name<mark style="color:red;">\*</mark>   | String   | Tournament Name                                       |
| description<mark style="color:red;">\*</mark>        | String   | Tournament Description                                |
| start\_time<mark style="color:red;">\*</mark>        | Datetime | Tournament Start Time                                 |
| end\_time<mark style="color:red;">\*</mark>          | Datetime | Tournament End Time                                   |
| participant\_limit<mark style="color:red;">\*</mark> | Integer  | Limit No. of Participant, see hint below              |
| tournament\_type<mark style="color:red;">\*</mark>   | String   | leaderboard, single\_elim, double\_elim, round\_robin |

#### Headers

| Name                                        | Type   | Description  |
| ------------------------------------------- | ------ | ------------ |
| X-Api-Key<mark style="color:red;">\*</mark> | String | API Key      |
| Authorization                               | Bearer | Token Bearer |

{% tabs %}
{% tab title="200: OK Tournament Created" %}

```javascript
{
    "status": "success",
    "message": "Tournament 63804c7ede700 Created "
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
For `single_elim` and `double_elim` tournament type, `participant_limit` currently only support power of two numbers (2, 4, 8, 16, etc)

For `leaderboard` tournament type, use 0 for unlimited.

For `round_robin` tournament type,`participant_limit` must be even number.&#x20;
{% endhint %}

## Read Tournament Result

{% hint style="success" %}
Also available as Player API
{% endhint %}

## Read Tournament Result

<mark style="color:blue;">`GET`</mark> `[endpoint]/v3/tournament/read/[tournament_id]`

#### Path Parameters

| Name                                             | Type   | Description   |
| ------------------------------------------------ | ------ | ------------- |
| tournament\_id<mark style="color:red;">\*</mark> | String | Tournament ID |

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-Api-Key<mark style="color:red;">\*</mark> | String | API Key     |

{% tabs %}
{% tab title="200: OK Single Elimination" %}

```javascript
{
    "status": "success",
    "tournament_data": {
        "tournament_id": "6360e665edf88",
        "game_id": "DJAKSFNJSA",
        "tournament_name": "Test Tournament",
        "description": "lorem ipsum dolor sit amet",
        "start_time": "2022-11-03 00:00:00",
        "end_time": "2022-12-03 00:00:00",
        "tournament_type": "single_elim",
        "participant_limit": 8
    },
    "tournament_result": [
        {
            "id": 1,
            "round_no": 1,
            "match_no": 1,
            "komo_username": "leoleo",
            "status": "W",
            "placeholder": "Player Slot 1"
        },
        {
            "id": 2,
            "round_no": 1,
            "match_no": 1,
            "komo_username": "maymay",
            "status": "L",
            "placeholder": "Player Slot 2"
        },
        {
            "id": 3,
            "round_no": 1,
            "match_no": 2,
            "komo_username": "Aviabee",
            "status": "W",
            "placeholder": "Player Slot 3"
        },
        {
            "id": 4,
            "round_no": 1,
            "match_no": 2,
            "komo_username": "Kazky",
            "status": "L",
            "placeholder": "Player Slot 4"
        },
        {
            "id": 5,
            "round_no": 1,
            "match_no": 3,
            "komo_username": "bogei",
            "status": "L",
            "placeholder": "Player Slot 5"
        },
        {
            "id": 6,
            "round_no": 1,
            "match_no": 3,
            "komo_username": "bambang",
            "status": "W",
            "placeholder": "Player Slot 6"
        },
        {
            "id": 7,
            "round_no": 1,
            "match_no": 4,
            "komo_username": "yrdna",
            "status": "L",
            "placeholder": "Player Slot 7"
        },
        {
            "id": 8,
            "round_no": 1,
            "match_no": 4,
            "komo_username": "komochess",
            "status": "W",
            "placeholder": "Player Slot 8"
        },
        {
            "id": 9,
            "round_no": 2,
            "match_no": 5,
            "komo_username": "leoleo",
            "status": "L",
            "placeholder": "Winner Match #1"
        },
        {
            "id": 10,
            "round_no": 2,
            "match_no": 5,
            "komo_username": "Aviabee",
            "status": "W",
            "placeholder": "Winner Match #2"
        },
        {
            "id": 11,
            "round_no": 2,
            "match_no": 6,
            "komo_username": "bambang",
            "status": "L",
            "placeholder": "Winner Match #3"
        },
        {
            "id": 12,
            "round_no": 2,
            "match_no": 6,
            "komo_username": "komochess",
            "status": "W",
            "placeholder": "Winner Match #4"
        },
        {
            "id": 13,
            "round_no": 3,
            "match_no": 7,
            "komo_username": "Aviabee",
            "status": "W",
            "placeholder": "Winner Match #5"
        },
        {
            "id": 14,
            "round_no": 3,
            "match_no": 7,
            "komo_username": "komochess",
            "status": "L",
            "placeholder": "Winner Match #6"
        }
    ]
}
```

{% endtab %}

{% tab title="200: OK Round Robin" %}

```javascript
{
    "status": "success",
    "tournament_data": {
        "tournament_id": "63843297e5bbf",
        "game_id": "komowars",
        "tournament_name": "Round Robin Tournament",
        "description": "lorem ipsum dolor sit amet",
        "start_time": "2022-12-03 00:00:00",
        "end_time": "2023-12-13 00:00:00",
        "tournament_type": "round_robin",
        "participant_limit": 10
    },
    "tournament_result": [
        {
            "id": 1,
            "round_no": 1,
            "match_no": 1,
            "placeholder_A": "Player Slot #1",
            "placeholder_B": "Player Slot #6",
            "komo_username_A": "pigroast",
            "komo_username_B": "bambang",
            "match_winner": "pigroast"
        },
        {
            "id": 2,
            "round_no": 1,
            "match_no": 2,
            "placeholder_A": "Player Slot #2",
            "placeholder_B": "Player Slot #7",
            "komo_username_A": "Aviabee",
            "komo_username_B": "maymay",
            "match_winner": "Aviabee"
        },
        {
            "id": 3,
            "round_no": 1,
            "match_no": 3,
            "placeholder_A": "Player Slot #3",
            "placeholder_B": "Player Slot #8",
            "komo_username_A": "kazky",
            "komo_username_B": "ainuka",
            "match_winner": "kazky"
        },
        {
            "id": 4,
            "round_no": 1,
            "match_no": 4,
            "placeholder_A": "Player Slot #4",
            "placeholder_B": "Player Slot #9",
            "komo_username_A": "leoleole",
            "komo_username_B": "Eful",
            "match_winner": "Eful"
        },
        {
            "id": 5,
            "round_no": 1,
            "match_no": 5,
            "placeholder_A": "Player Slot #5",
            "placeholder_B": "Player Slot #10",
            "komo_username_A": "b0gei",
            "komo_username_B": "polycrest",
            "match_winner": "polycrest"
        },
        {
            "id": 6,
            "round_no": 2,
            "match_no": 1,
            "placeholder_A": "Player Slot #1",
            "placeholder_B": "Player Slot #7",
            "komo_username_A": "pigroast",
            "komo_username_B": "maymay",
            "match_winner": "X"
        },
        {
            "id": 7,
            "round_no": 2,
            "match_no": 2,
            "placeholder_A": "Player Slot #3",
            "placeholder_B": "Player Slot #8",
            "komo_username_A": "kazky",
            "komo_username_B": "ainuka",
            "match_winner": "X"
        },
        {
            "id": 8,
            "round_no": 2,
            "match_no": 3,
            "placeholder_A": "Player Slot #4",
            "placeholder_B": "Player Slot #9",
            "komo_username_A": "leoleole",
            "komo_username_B": "Eful",
            "match_winner": "X"
        },
        {
            "id": 9,
            "round_no": 2,
            "match_no": 4,
            "placeholder_A": "Player Slot #5",
            "placeholder_B": "Player Slot #10",
            "komo_username_A": "b0gei",
            "komo_username_B": "polycrest",
            "match_winner": "X"
        },
        {
            "id": 10,
            "round_no": 2,
            "match_no": 5,
            "placeholder_A": "Player Slot #6",
            "placeholder_B": "Player Slot #2",
            "komo_username_A": "bambang",
            "komo_username_B": "Aviabee",
            "match_winner": "X"
        },
        {
            "id": 11,
            "round_no": 3,
            "match_no": 1,
            "placeholder_A": "Player Slot #1",
            "placeholder_B": "Player Slot #8",
            "komo_username_A": "pigroast",
            "komo_username_B": "ainuka",
            "match_winner": "X"
        },
        {
            "id": 12,
            "round_no": 3,
            "match_no": 2,
            "placeholder_A": "Player Slot #4",
            "placeholder_B": "Player Slot #9",
            "komo_username_A": "leoleole",
            "komo_username_B": "Eful",
            "match_winner": "X"
        },
        {
            "id": 13,
            "round_no": 3,
            "match_no": 3,
            "placeholder_A": "Player Slot #5",
            "placeholder_B": "Player Slot #10",
            "komo_username_A": "b0gei",
            "komo_username_B": "polycrest",
            "match_winner": "X"
        },
        {
            "id": 14,
            "round_no": 3,
            "match_no": 4,
            "placeholder_A": "Player Slot #6",
            "placeholder_B": "Player Slot #2",
            "komo_username_A": "bambang",
            "komo_username_B": "Aviabee",
            "match_winner": "X"
        },
        {
            "id": 15,
            "round_no": 3,
            "match_no": 5,
            "placeholder_A": "Player Slot #7",
            "placeholder_B": "Player Slot #3",
            "komo_username_A": "maymay",
            "komo_username_B": "kazky",
            "match_winner": "X"
        },
        {
            "id": 16,
            "round_no": 4,
            "match_no": 1,
            "placeholder_A": "Player Slot #1",
            "placeholder_B": "Player Slot #9",
            "komo_username_A": "pigroast",
            "komo_username_B": "Eful",
            "match_winner": "X"
        },
        {
            "id": 17,
            "round_no": 4,
            "match_no": 2,
            "placeholder_A": "Player Slot #5",
            "placeholder_B": "Player Slot #10",
            "komo_username_A": "b0gei",
            "komo_username_B": "polycrest",
            "match_winner": "X"
        },
        {
            "id": 18,
            "round_no": 4,
            "match_no": 3,
            "placeholder_A": "Player Slot #6",
            "placeholder_B": "Player Slot #2",
            "komo_username_A": "bambang",
            "komo_username_B": "Aviabee",
            "match_winner": "X"
        },
        {
            "id": 19,
            "round_no": 4,
            "match_no": 4,
            "placeholder_A": "Player Slot #7",
            "placeholder_B": "Player Slot #3",
            "komo_username_A": "maymay",
            "komo_username_B": "kazky",
            "match_winner": "X"
        },
        {
            "id": 20,
            "round_no": 4,
            "match_no": 5,
            "placeholder_A": "Player Slot #8",
            "placeholder_B": "Player Slot #4",
            "komo_username_A": "ainuka",
            "komo_username_B": "leoleole",
            "match_winner": "X"
        },
        {
            "id": 21,
            "round_no": 5,
            "match_no": 1,
            "placeholder_A": "Player Slot #1",
            "placeholder_B": "Player Slot #10",
            "komo_username_A": "pigroast",
            "komo_username_B": "polycrest",
            "match_winner": "X"
        },
        {
            "id": 22,
            "round_no": 5,
            "match_no": 2,
            "placeholder_A": "Player Slot #6",
            "placeholder_B": "Player Slot #2",
            "komo_username_A": "bambang",
            "komo_username_B": "Aviabee",
            "match_winner": "X"
        },
        {
            "id": 23,
            "round_no": 5,
            "match_no": 3,
            "placeholder_A": "Player Slot #7",
            "placeholder_B": "Player Slot #3",
            "komo_username_A": "maymay",
            "komo_username_B": "kazky",
            "match_winner": "X"
        },
        {
            "id": 24,
            "round_no": 5,
            "match_no": 4,
            "placeholder_A": "Player Slot #8",
            "placeholder_B": "Player Slot #4",
            "komo_username_A": "ainuka",
            "komo_username_B": "leoleole",
            "match_winner": "X"
        },
        {
            "id": 25,
            "round_no": 5,
            "match_no": 5,
            "placeholder_A": "Player Slot #9",
            "placeholder_B": "Player Slot #5",
            "komo_username_A": "Eful",
            "komo_username_B": "b0gei",
            "match_winner": "X"
        },
        {
            "id": 26,
            "round_no": 6,
            "match_no": 1,
            "placeholder_A": "Player Slot #1",
            "placeholder_B": "Player Slot #2",
            "komo_username_A": "pigroast",
            "komo_username_B": "Aviabee",
            "match_winner": "X"
        },
        {
            "id": 27,
            "round_no": 6,
            "match_no": 2,
            "placeholder_A": "Player Slot #7",
            "placeholder_B": "Player Slot #3",
            "komo_username_A": "maymay",
            "komo_username_B": "kazky",
            "match_winner": "X"
        },
        {
            "id": 28,
            "round_no": 6,
            "match_no": 3,
            "placeholder_A": "Player Slot #8",
            "placeholder_B": "Player Slot #4",
            "komo_username_A": "ainuka",
            "komo_username_B": "leoleole",
            "match_winner": "X"
        },
        {
            "id": 29,
            "round_no": 6,
            "match_no": 4,
            "placeholder_A": "Player Slot #9",
            "placeholder_B": "Player Slot #5",
            "komo_username_A": "Eful",
            "komo_username_B": "b0gei",
            "match_winner": "X"
        },
        {
            "id": 30,
            "round_no": 6,
            "match_no": 5,
            "placeholder_A": "Player Slot #10",
            "placeholder_B": "Player Slot #6",
            "komo_username_A": "polycrest",
            "komo_username_B": "bambang",
            "match_winner": "X"
        },
        {
            "id": 31,
            "round_no": 7,
            "match_no": 1,
            "placeholder_A": "Player Slot #1",
            "placeholder_B": "Player Slot #3",
            "komo_username_A": "pigroast",
            "komo_username_B": "kazky",
            "match_winner": "X"
        },
        {
            "id": 32,
            "round_no": 7,
            "match_no": 2,
            "placeholder_A": "Player Slot #8",
            "placeholder_B": "Player Slot #4",
            "komo_username_A": "ainuka",
            "komo_username_B": "leoleole",
            "match_winner": "X"
        },
        {
            "id": 33,
            "round_no": 7,
            "match_no": 3,
            "placeholder_A": "Player Slot #9",
            "placeholder_B": "Player Slot #5",
            "komo_username_A": "Eful",
            "komo_username_B": "b0gei",
            "match_winner": "X"
        },
        {
            "id": 34,
            "round_no": 7,
            "match_no": 4,
            "placeholder_A": "Player Slot #10",
            "placeholder_B": "Player Slot #6",
            "komo_username_A": "polycrest",
            "komo_username_B": "bambang",
            "match_winner": "X"
        },
        {
            "id": 35,
            "round_no": 7,
            "match_no": 5,
            "placeholder_A": "Player Slot #2",
            "placeholder_B": "Player Slot #7",
            "komo_username_A": "Aviabee",
            "komo_username_B": "maymay",
            "match_winner": "X"
        },
        {
            "id": 36,
            "round_no": 8,
            "match_no": 1,
            "placeholder_A": "Player Slot #1",
            "placeholder_B": "Player Slot #4",
            "komo_username_A": "pigroast",
            "komo_username_B": "leoleole",
            "match_winner": "X"
        },
        {
            "id": 37,
            "round_no": 8,
            "match_no": 2,
            "placeholder_A": "Player Slot #9",
            "placeholder_B": "Player Slot #5",
            "komo_username_A": "Eful",
            "komo_username_B": "b0gei",
            "match_winner": "X"
        },
        {
            "id": 38,
            "round_no": 8,
            "match_no": 3,
            "placeholder_A": "Player Slot #10",
            "placeholder_B": "Player Slot #6",
            "komo_username_A": "polycrest",
            "komo_username_B": "bambang",
            "match_winner": "X"
        },
        {
            "id": 39,
            "round_no": 8,
            "match_no": 4,
            "placeholder_A": "Player Slot #2",
            "placeholder_B": "Player Slot #7",
            "komo_username_A": "Aviabee",
            "komo_username_B": "maymay",
            "match_winner": "X"
        },
        {
            "id": 40,
            "round_no": 8,
            "match_no": 5,
            "placeholder_A": "Player Slot #3",
            "placeholder_B": "Player Slot #8",
            "komo_username_A": "kazky",
            "komo_username_B": "ainuka",
            "match_winner": "X"
        },
        {
            "id": 41,
            "round_no": 9,
            "match_no": 1,
            "placeholder_A": "Player Slot #1",
            "placeholder_B": "Player Slot #5",
            "komo_username_A": "pigroast",
            "komo_username_B": "b0gei",
            "match_winner": "X"
        },
        {
            "id": 42,
            "round_no": 9,
            "match_no": 2,
            "placeholder_A": "Player Slot #10",
            "placeholder_B": "Player Slot #6",
            "komo_username_A": "polycrest",
            "komo_username_B": "bambang",
            "match_winner": "X"
        },
        {
            "id": 43,
            "round_no": 9,
            "match_no": 3,
            "placeholder_A": "Player Slot #2",
            "placeholder_B": "Player Slot #7",
            "komo_username_A": "Aviabee",
            "komo_username_B": "maymay",
            "match_winner": "X"
        },
        {
            "id": 44,
            "round_no": 9,
            "match_no": 4,
            "placeholder_A": "Player Slot #3",
            "placeholder_B": "Player Slot #8",
            "komo_username_A": "kazky",
            "komo_username_B": "ainuka",
            "match_winner": "X"
        },
        {
            "id": 45,
            "round_no": 9,
            "match_no": 5,
            "placeholder_A": "Player Slot #4",
            "placeholder_B": "Player Slot #9",
            "komo_username_A": "leoleole",
            "komo_username_B": "Eful",
            "match_winner": "X"
        }
    ]
}
```

{% endtab %}
{% endtabs %}

## Managing Single Elimination Type Tournament

After creating tournament with tournament\_type `single_elim`, we automatically create a bracket.

We also provide preview of the bracket here:

{% hint style="info" %}
\[endpoint]/view-tournament/\[tournament\_id]&#x20;

Preview: [Tournament #6360e665edf88](https://api.komoverse.io/view-tournament/6360e665edf88)
{% endhint %}

## Asigning Player Into Player Slot

<mark style="color:green;">`POST`</mark> `[endpoint]/v3/tournament/bracket/assign`

To see availability of player slot in the bracket, find the **null** value on `komo_username` after getting `/v2/tournament/read/[tournament_id]`

#### Query Parameters

| Name                                             | Type    | Description            |
| ------------------------------------------------ | ------- | ---------------------- |
| tournament\_id<mark style="color:red;">\*</mark> | String  | Tournament ID          |
| komo\_username<mark style="color:red;">\*</mark> | String  | KOMO Username          |
| player\_slot<mark style="color:red;">\*</mark>   | Integer | Player Slot in Bracket |

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-Api-Key<mark style="color:red;">\*</mark> | String | API Key     |

{% tabs %}
{% tab title="403: Forbidden Slot already used" %}

```javascript
{
    "status": "error",
    "message": "Slot Already Occupied by komochess"
}
```

{% endtab %}

{% tab title="200: OK Slot assigned" %}

```javascript
{
    "status": "success",
    "message": "Player Slot 1 Assigned to Aviabee"
}
```

{% endtab %}
{% endtabs %}

## Update Bracket Winner

<mark style="color:green;">`POST`</mark> `[endpoint]/v3/tournament/bracket/update`

Use this API to update match winner from a bracket match. It will also automatically move the winner into next bracket.

#### Query Parameters

| Name                                             | Type    | Description                   |
| ------------------------------------------------ | ------- | ----------------------------- |
| tournament\_id<mark style="color:red;">\*</mark> | String  | Tournament ID                 |
| match\_no<mark style="color:red;">\*</mark>      | Integer | Match Number in Bracket       |
| match\_winner<mark style="color:red;">\*</mark>  | String  | KOMO Username of Match Winner |

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-Api-Key<mark style="color:red;">\*</mark> | String | API Key     |

{% tabs %}
{% tab title="200: OK Bracket Updated" %}

```javascript
{
    "status": "success",
    "message": "Tournament Bracket Successfully Updated"
}
```

{% endtab %}
{% endtabs %}

## Managing Round Robin Type Tournament

After creating tournament with tournament\_type `round_robin`, we automatically create a match schedule.

We also provide preview of the schedule here:

{% hint style="info" %}
\[endpoint]/view-round-robin/\[tournament\_id]&#x20;

Preview: [Tournament #63843297e5bbf](https://api.komoverse.io/view-round-robin/63843297e5bbf)
{% endhint %}

## Asigning Player Into Player Slot

<mark style="color:green;">`POST`</mark> `[endpoint]/v3/tournament/robin/assign`

To see availability of player slot in the bracket, find the **null** value on `komo_username_A` after getting `/v2/tournament/read/[tournament_id]`

#### Query Parameters

| Name                                             | Type    | Description                         |
| ------------------------------------------------ | ------- | ----------------------------------- |
| tournament\_id<mark style="color:red;">\*</mark> | String  | Tournament ID                       |
| komo\_username<mark style="color:red;">\*</mark> | String  | KOMO Username                       |
| player\_slot<mark style="color:red;">\*</mark>   | Integer | Player Slot in Round Robin Schedule |

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-Api-Key<mark style="color:red;">\*</mark> | String | API Key     |

{% tabs %}
{% tab title="403: Forbidden Slot already used" %}

```javascript
{
    "status": "error",
    "message": "Slot Already Occupied by Aviabee"
}
```

{% endtab %}

{% tab title="200: OK Slot assigned" %}

```javascript
{
    "status": "success",
    "message": "Player Slot #2 Assigned to Aviabee"
}
```

{% endtab %}
{% endtabs %}

## Update Match Winner

<mark style="color:green;">`POST`</mark> `[endpoint]/v3/tournament/robin/update`

Use this API to update match winner from a round robin match

#### Query Parameters

| Name                                             | Type    | Description                   |
| ------------------------------------------------ | ------- | ----------------------------- |
| tournament\_id<mark style="color:red;">\*</mark> | String  | Tournament ID                 |
| match\_id<mark style="color:red;">\*</mark>      | Integer | Match ID                      |
| match\_winner<mark style="color:red;">\*</mark>  | String  | KOMO Username of Match Winner |

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-Api-Key<mark style="color:red;">\*</mark> | String | API Key     |

{% tabs %}
{% tab title="200: OK Winner Updated" %}

```javascript
{
    "status": "success",
    "message": "Match Winner Updated"
}
```

{% endtab %}

{% tab title="403: Forbidden Winner is not on the match" %}

```javascript
{
    "status": "error",
    "message": "match_winner is Not On This match_id"
}
```

{% endtab %}
{% endtabs %}
