# Wordle

## Game logic

<details>

<summary>Game Logic code</summary>

```python
import random
round_count = 20
def init_game(game_settings, ref_data):
    return {
        "player_turn_idx": 0,
        "answers": [random.choice(ref_data["words"]).upper() for i in range(round_count)],
        "round_index": 0,
        "guesses_each_round": [{
            "guesses": []
        } for i in range(round_count)],
        "scores": []
    }

def guess(state, ref_data, word):
    if len(word) != 5:
        raise InvalidActionError("Guesses should be 5 letters long")
    word = word.upper()
    round_index = state["round_index"]
    target = state["answers"][round_index]
    letter_bag = list(target)
    result = ['', '', '', '', '']

    for i in range(len(word)):
        if word[i] == target[i]:
            result[i] = 'G'
            letter_bag.remove(word[i])
    for i in range(len(word)):
        if result[i] == 'G':
            continue
        if word[i] in letter_bag:
            result[i] = 'Y'
            letter_bag.remove(word[i])
        else:
            result[i] = 'B'
    guesses_this_round = state["guesses_each_round"][round_index]["guesses"]
    guesses_this_round.append({
            "guess": word,
            "result": "".join(result)
        })

    if word == target or len(guesses_this_round) == 6:
        if round_index < round_count - 1:
            state["round_index"] += 1
        if word == target:
            if len(guesses_this_round) == 1:
                state["scores"].append(10)
            elif len(guesses_this_round) == 2:
                state["scores"].append(10)
            elif len(guesses_this_round) == 3:
                state["scores"].append(6)
            elif len(guesses_this_round) == 4:
                state["scores"].append(3)
            elif len(guesses_this_round) == 5:
                state["scores"].append(2)
            elif len(guesses_this_round) == 6:
                state["scores"].append(1)
        else:
            state["scores"].append(-5)

    return state

def get_game_result(state, ref_data):
    round_index = state["round_index"]
    target = state["answers"][round_index]
    guesses_this_round = state["guesses_each_round"][round_index]["guesses"]
    if (round_index == round_count - 1 and 
        len(guesses_this_round) > 0 and 
        (len(guesses_this_round) == 6 or guesses_this_round[-1]["guess"] == target)):
        return {
            "game_result": "SinglePlayerCompleted",
            "winner_idx": 0,
            "score": sum(state["scores"])
        }

    return {
        "game_result": "NoWinnerYet",
    }


def get_player_states(state, ref_data):
    player_states = []
    round_index = state["round_index"]
    target = state["answers"][round_index]
    guesses_this_round = state["guesses_each_round"][round_index]["guesses"]
    for i in range(1):
        obfuscated_answers = []
        for i in range(len(state["answers"])):
            if round_index > i:
                obfuscated_answers.append(state["answers"][i])
            elif round_index == i and len(state["guesses_each_round"][round_index]["guesses"]) == 6:
                obfuscated_answers.append(state["answers"][i])
            elif round_index == i and len(guesses_this_round) > 0 and guesses_this_round[-1]["guess"] == target:
                obfuscated_answers.append(state["answers"][i])
            else:
                obfuscated_answers.append("*****")
        player_states.append({
            "player_turn_idx": state["player_turn_idx"],
            "round_index": state["round_index"],
            "guesses_each_round": state["guesses_each_round"],
            "scores": state["scores"],
            "answers": obfuscated_answers
        })
    return player_states

```

</details>

## Game state schema

```protobuf
message State {
  int32 player_turn_idx = 1;
  int32 round_index = 2;
  repeated GuessesEachRound = 3;
  repeated int32 scores = 4;
  repeated string answers = 5;
}
```

```protobuf
message GuessesEachRound {
  repeated Guess guesses = 1;
}
```

```protobuf
message Guess {
  string guess = 1;
  string result = 2;
}
```

```protobuf
message refData {
  repeated string words = 1;
}
```

## Action schema

```javascript
guess(string word)
```

[Start building now](https://botpot.ai/game/wordle)


---

# 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://doc.botpot.ai/games/explore/wordle.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.
