Skip to content

Commit

Permalink
feat: add wordle proxy_program and target program.
Browse files Browse the repository at this point in the history
  • Loading branch information
aiqubits committed Jul 7, 2024
1 parent 3be953c commit c2605fc
Show file tree
Hide file tree
Showing 21 changed files with 622 additions and 221 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [main]
push:
branches: [main]
workflow_dispatch:

env:
CARGO_TERM_COLOR: always
Expand All @@ -28,10 +29,12 @@ jobs:
cargo fmt --all --check
cargo clippy --all-targets -- -D warnings -A unused-imports
cargo b -r
cargo t
- name: Session Check and test
run: |
cd session
cargo fmt --all --check
cargo clippy --all-targets -- -D warnings -A unused-imports
cargo b -r
cargo b -r
cargo t
Binary file added 1720184706536.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1720185307791.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1720185876769.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Task Description
For this assignment, you are tasked with writing the Wordle game.

Wordle is a captivating word-guessing game that has become popular for its simplicity and addictive gameplay. The goal is to guess a hidden word within a limited number of attempts.

The game board consists of six rows, each allowing the player to input a word. Upon entering a word, the player receives feedback indicating the presence of letters in the hidden word and their correct positions. If a letter is present but in the wrong position, it may be highlighted in a different color or marked with a distinct symbol. Players utilize these clues to deduce the correct letters and their placements.

The game challenges players to guess the word with the fewest attempts, under time constraints and limited attempts, adding excitement and suspense.

# Project Structure
Break down your Wordle game into two programs for a more engaging and flexible experience. The Wordle program will handle the core functionalities, such as selecting a random word from a list and evaluating guesses. The Game Session program will manage user interactions, keep track of the game state, and enforce time constraints. This division aims to create a modular, flexible system that enhances the gaming experience.

1. Description of the Wordle program:

Contains "start the game" and "check the word" functions.
A word bank exists within the program for selecting a random word at the game's start.
"Start the game" function initiates the game and selects a random word.
"Check the word" function assesses the player's guess against the hidden word, providing feedback on correct letter positions.

2. Description of the Game Session program:

Manages interactions with the Wordle program and oversees the gameplay.
Tracks previous responses and the number of attempts.
Monitors the elapsed time since the game started to manage time constraints and events.

3. Interaction Between the Programs:

The user initiates the game by sending a message to the Game Session program.
The Game Session program invokes the Wordle program's "start the game" function.
The user submits their guesses to the Game Session program, which forwards them to the Wordle program's "check the word" function.
The Wordle program returns feedback on the guess's accuracy and letter positions.
The Game Session program analyzes the result, tracking attempts and time.

4. Key Implementation Aspects:

The Game Session program requires mechanisms to store data about previous moves and track time.
Efficient interaction with the Wordle program through data exchange and response handling is crucial.

![Alt text](1720185876769.jpg)

# Deployment and Use
https://idea.gear-tech.io/
wss://testnet.vara.network

aiqubits_wordle_game program id
0x98de5336075b2550ff6ee7b3ec4b72b4856412a5df580f4f5118fcb0e87f7a25

https://idea.gear-tech.io/programs/0x98de5336075b2550ff6ee7b3ec4b72b4856412a5df580f4f5118fcb0e87f7a25?node=wss%3A%2F%2Ftestnet.vara.network

aiqubits_session_game program id
0xdb3552cb90e74ad9bc15f4804830e7e01a34bea4f4c2093eb4657ffdecb1a8b6

https://idea.gear-tech.io/programs/0xdb3552cb90e74ad9bc15f4804830e7e01a34bea4f4c2093eb4657ffdecb1a8b6?node=wss%3A%2F%2Ftestnet.vara.network

![Alt text](1720184706536.jpg)
![Alt text](1720185307791.jpg)
12 changes: 12 additions & 0 deletions session/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ version = "0.1.0"
edition = "2021"

[dependencies]
gstd = { git = "https://github.com/gear-tech/gear.git", tag = "v1.4.1",features = ["debug"] }
gstd = { git = "https://github.com/gear-tech/gear.git", tag = "v1.4.1", features = ["debug"] }
parity-scale-codec = { version = "3", default-features = false }
scale-info = { version = "2", default-features = false }
session-game-io.path = "io"
wordle-game-io.path = "../wordle/io"

[build-dependencies]
gear-wasm-builder = { git = "https://github.com/gear-tech/gear.git", tag = "v1.4.1" }
session-game-io.path = "io"
wordle-game-io.path = "../wordle/io"

[dev-dependencies]
gstd = { git = "https://github.com/gear-tech/gear.git", tag = "v1.4.1" }
gstd = { git = "https://github.com/gear-tech/gear.git", tag = "v1.4.1", features = ["debug"] }
gmeta = { git = "https://github.com/gear-tech/gear.git", tag = "v1.4.1" }
gtest = { git = "https://github.com/gear-tech/gear.git", tag = "v1.4.1" }
parity-scale-codec = { version = "3", default-features = false }
scale-info = { version = "2", default-features = false }
session-game-io.path = "io"
wordle-game-io.path = "../wordle/io"
4 changes: 3 additions & 1 deletion session/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use session_game_io::WordleMetadata;

fn main() {
gear_wasm_builder::build();
gear_wasm_builder::build_with_metadata::<WordleMetadata>();
}
11 changes: 11 additions & 0 deletions session/io/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "session-game-io"
version = "0.1.0"
edition = "2021"

[dependencies]
gstd = { git = "https://github.com/gear-tech/gear.git", tag = "v1.4.1" }
gmeta = { git = "https://github.com/gear-tech/gear.git", tag = "v1.4.1" }
parity-scale-codec = { version = "3", default-features = false }
scale-info = { version = "2", default-features = false }
enum-iterator = "2.1.0"
83 changes: 83 additions & 0 deletions session/io/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#![no_std]
use gmeta::{InOut, Metadata};
use gstd::{collections::HashMap, prelude::*, ActorId, MessageId};

// the metadata to be used by the [IDEA](https://idea.gear-tech.io/programs?node=wss%3A%2F%2Ftestnet.vara.network) portal.
#[derive(Debug, Default, Clone, Encode, Decode, TypeInfo)]
pub struct WordleMetadata;

impl Metadata for WordleMetadata {
type Init = ();
type Handle = InOut<Action, SessionStatus>;
type Others = ();
type Reply = ();
type Signal = ();
type State = InOut<StateQuery, StateQueryReply>;
}

// Id of a User initiating the action is Key, Value is Session.
// pub type State = Vec<(ActorId, Session)>;
pub type State = HashMap<ActorId, Session>;

type SentMessageId = MessageId;
type OriginalMessageId = MessageId;

#[derive(Debug, Clone, Encode, Decode, TypeInfo, PartialEq, Eq)]
#[codec(crate = gstd::codec)]
#[scale_info(crate = gstd::scale_info)]
pub struct Session {
// pub target_program_id: ActorId, // target program address
pub msg_ids: (SentMessageId, OriginalMessageId), // tuple containing the identifier of a message sent to a Target program, the identifier of a message current program.
pub session_status: SessionStatus,
pub tries_number: u8,
}

#[derive(Debug, Clone, Encode, Decode, TypeInfo, PartialEq, Eq)]
#[codec(crate = gstd::codec)]
#[scale_info(crate = gstd::scale_info)]
pub enum SessionStatus {
None,
GameStarted,
Waiting,
GameOver(Outcome),
WordChecked {
user: ActorId,
correct_positions: Vec<u8>,
contained_in_word: Vec<u8>,
},
InvalidWord,
NoReplyReceived,
}

#[derive(Debug, Clone, Encode, Decode, TypeInfo, PartialEq, Eq)]
#[codec(crate = gstd::codec)]
#[scale_info(crate = gstd::scale_info)]
pub enum Action {
StartGame,
CheckWord(String),
CheckGameStatus,
}

#[derive(Debug, Clone, Encode, Decode, TypeInfo, PartialEq, Eq)]
#[codec(crate = gstd::codec)]
#[scale_info(crate = gstd::scale_info)]
pub enum Outcome {
Win,
Lose,
}

#[derive(Debug, Clone, Encode, Decode, TypeInfo, PartialEq, Eq)]
#[codec(crate = gstd::codec)]
#[scale_info(crate = gstd::scale_info)]
pub enum StateQuery {
All,
Player(ActorId),
}

#[derive(Debug, Clone, Encode, Decode, TypeInfo, PartialEq, Eq)]
#[codec(crate = gstd::codec)]
#[scale_info(crate = gstd::scale_info)]
pub enum StateQueryReply {
All(Vec<ActorId>),
Game(Session),
}
Loading

0 comments on commit c2605fc

Please sign in to comment.