GithubHelp home page GithubHelp logo

sphynx / rokumon Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 1.0 19.99 MB

Implementation of Rokumon game

License: MIT License

Rust 79.36% Shell 0.29% HTML 0.43% JavaScript 16.35% CSS 3.57%
rokumon rust ai alphabeta game webassembly wasm wasm-pack webpack

rokumon's People

Contributors

sphynx avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ex1stgames

rokumon's Issues

Fix "Fight" rule

Currently the rule is implemented as "Fight" is possible if "at least on die is yours". This actually includes the case when both dice are yours. However, according to Charles, the fight should only be allow when there are two dice: one is your and one is your opponent's.

The fixes should be applied to game.rs in rokumon_core (in validate_move function). Also, we can apply them in the UI where availability of the Fight button is checked: canFight function in game.js

Make WASM file take less space

As explored in #16, our WASM size is currently more than 300k, which is potentially large for Web.

Investigate what can be done with that, perhaps we can avoid building packages like rand (and just use rand() from js-sys) or optimize compilation for size (trying not to neglect speed at the same time).

Add a custom RunCondition for WebAssembly using websys

Currently, the bot uses std::time to handle duration running condition (i.e. to measure the time which it can use to analyse the move). std::time is not supported on wasm32-unknown-unknown, so we need to have a custom implementation of rubot::RunCondition which will probably use websys. We'll need to enable it conditionally for wasm-aware build of the core library (i.e. under "for_wasm" feature).

Fix "request of a dependency is an expression" warning

Currently npm start runs with the following warning:

Compiled with warnings.

../rokumon_wasm/pkg/rokumon_wasm_bg.js
Critical dependency: the request of a dependency is an expression

I believe it was introduced by compiling rand Rust package with wasm-bindgen feature.

Handle `Back` in browser properly to transition back to Game Setup screen

Now, when I move from Game Setup screen to the Game screen, it all happens inside a single page (I basically do the transition with JavaScript, just rendering different components), even though it feels like we are going to another page.

Therefore, just clicking Back button on the Game screen does not take you back to the Game Setup screen and instead just takes you on the previous web page (sometime that's not even Rokumon page).

We should figure out how to handle that Back putton in JS and just revert the app state back to GameSetup.

Prepare "production" build of React app

We should try publishing it in "release" mode (as opposed to "dev") and see how big it is and how it looks (CSS/JS/WASM). Then we can see if it's ok or that we should work on trying to make it smaller.

This also includes minimizing the compiled WASM size (i.e. using -c flag to ask compiler to optimize for generated code size).

Introduce GameManager in web

We should have a component which orchestrates getting moves from the players (be it human players or bots). Currently it's done in a rather ad hoc manner: it's hardcoded for Human vs AI play, not being able to handle Human vs Human or Bot vs Bot games.

Report game end

We need to show a message when the game ends, disable normal controls, showing an option to start a new game.

Bot panics when there are no possible moves

We should consider "no moves" a normal situation when the player to moves just loses, however current code expects that there always at least some move and panics otherwise (because it uses unwrap from Option).

Thanks to @illegal for spotting the bug!

Here is an example of a position demonstrating this bug (without "fight" or "surprise" moves):

Resulting position:

Jade[] Gold[B1 < R2] Gold[B1 < R2]
Jade[B1] Gold[B1 < R2] Jade[R2 < B1] Jade[]
Player 1: []
Player 2: []
to move: Player 2

Running AI with duration 1s...
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/ai.rs:163:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Full log is available here: https://gist.github.com/illegal/afd89aef9356b7799c892bd99bbe86df

Split the crate into lib and binary crates

It would be nice to have a separate lib-crate with just the core parts and data structures of Rokumon, without the parts required by the console executable (for example moves parser, command line options handling, etc.). Then this crate can be used for WebAssembly compilation

Add Criterion benchmarks

We can do it for:

  • perft, to test the speed of move generator โ€“โ€“ definitely useful.
  • selecting move from the bot (say up to particular, short depth).

We should do it for various combinations of rules:

  • No Fight, no Surprise
  • Only Fight
  • Both

And perhaps for several positions:

  • starting position
  • position after 3-4 moves
  • position somewhere in the middle of the game when most dice are out

Add support for the board from the last act of the rules

The one to play with Automa (hex-shaped with a fort in the middle).

For that we would need to implement the missing case marked with unimplemented!() in Board::new for Layout::Hex7. There are examples of creating new boards for other layouts: Rectangle6 and Bricks7.

Implement Automa

Automa is a bot described in the rules, basically a solo version of the game.

For that you'll need to check out the last page of the rules and then implement the algorithm for playing.

Add ability to save/load games from files

In this way if should be easy to reproduce certain games and situations.

We should also add a way of dumping games or current position to a file, so that it can be reproduced later.

The format can be as simple as options + sequence of moves. Then we create the game using those options and apply the moves sequentially.

Load WASM code only once

We should load WASM only once (since it's quite heavy) and just recreate the Game/Playground using WASM calls when creating another game. On the other hand, we don't want to load WASM at the very beginning, i.e. on Game Setup page, since it's not needed yet.

So, we should basically load WASM lazily, but keep it in memory and not to load it twice (or every time when creating a new Game as it's done now).

It's not very clear for me what is the idiomatic way to do it, I should read more about React lazy loading and overall approach to long calls/loads.

Consider multiple repetitions a draw

Sometimes when two bots are playing they start looping, coming back to the same position again and again. Since bots are mostly deterministic, they keep choosing the same option, so there is no point in continuing this and we should probably call it a draw (like three-fold repetition rule in chess).

Make `rokumon_core` errors library-style errors

We should probably migrate from deprecated failure crate and use anyhow and thiserror crates.

We should also consider errors in rokumon-core to be library errors, i.e. instead of using strings, we should use enums, so that web and console-ui clients can interpret and display those error differently and in whatever fashion they like. Then we can also localize them.

Add web screenshots to README.md

We should also explicitly mention WebAssembly part of the project, because currently README only tells about the command line interface.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.