Code Monkey home page Code Monkey logo

oppai-rs's Introduction

Oppai-rs

Logo

Oppai-rs (acronym for "OPen Points Artificial Intelligence") is an artificial intelligence for the game of points.

You can play with it using iced module.

Features

  • Two algorithms for searching the optimal move: UCT, Minimax.
  • Two implementations of Minimax search: PVS (a.k.a. NegaScout), MTD(f).
  • UCT tree reuse between moves.
  • Trajectories for moves pruning in the Minimax search tree.
  • Lock-free multi-threading for both Minimax and UCT.
  • Transposition table using Zobrist hashing for Minimax.
  • DFA-based patterns searching.
  • DSU to optimize capturing (behind a feature flag since it's good only for UCT).
  • Time-based and complexity-based calculations.
  • Generic ladders solver.

Running

Once you have rust installed on your system, compile with:

cargo build --release

Run with:

cargo run --release

or with:

./target/release/oppai-rs

If you are running the produced binary on the same CPU it was built on you might want to specify target-cpu flag:

RUSTFLAGS="-C target-cpu=native" \
  cargo build --release

Depending on your hardware it might increase the performance by up to 10%.

Testing

You can run test with:

cargo test

If you want to see log output during tests running you can use RUST_LOG environment variable:

RUST_LOG=debug cargo test

Also if you have nightly rust you can run benchmarks with:

cargo bench --features bench

Ideas

  • Best Node Search algorithm (see link).
  • Cache built DFA for fast patterns loading.
  • Fill debuts database.
  • Fill heuristics database.
  • Use patterns for UCT random games (see link).
  • Use patterns for Minimax best move prediction.
  • Complex estimating function for Minimax (see link)
  • Smart time control for UCT (see link).
  • Smart time control for Minimax.
  • Think on enemy's move.
  • Forbid typical losing ladders.
  • Fractional komi support.
  • Split trajectories by groups for Minimax and solve them independently.

License

This project is licensed under AGPL version 3 or (at your option) any later version. See LICENSE.txt for details.

Copyright (C) 2015-2024 Kurnevsky Evgeny, Vasya Novikov

oppai-rs's People

Contributors

kurnevsky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

vn971 baitcenter

oppai-rs's Issues

The `find_best_move` test sometimes fails.

Repro steps:

  1. cargo test find_best_move
  2. Repeat 10 times
  3. 30% of the time it will fail at src/minimax_test.rs:26:2 (depth = 7), usually finding Some(37) (6, 2) or Some(26) (5, 1) instead of the expected Some(36) (5, 2).
Logs for a failing case.
Starting minimax with depth 7 and player Red.
Calculating of our estimation. Player is Red
Starting parellel alpha beta with depth 7, player Red and beta 2147483647.
Moves in consideration: [(5, 3), (3, 5), (3, 1), (4, 1), (4, 6), (5, 1), (6, 2), (6, 4), (5, 2), (1, 3), (2, 2), (5, 5), (2, 4), (4, 2), (6, 3)].
Estimation for move (3, 5) is -2147483647, alpha is -2147483647, beta is 2147483647.
Estimation for move (5, 3) is 0, alpha is -2147483647, beta is 2147483647.
Estimation for move (3, 1) is 0, alpha is -2147483647, beta is 2147483647.
Estimation for move (4, 6) is 0, alpha is -2147483647, beta is 2147483647.
Estimation for move (6, 4) is 0, alpha is 0, beta is 2147483647.
Estimation for move (4, 1) is 0, alpha is -2147483647, beta is 2147483647.
Estimation for move (1, 3) is 0, alpha is 0, beta is 2147483647.
Estimation for move (5, 1) is 1, alpha is 0, beta is 2147483647.
Estimation for move (2, 2) is 0, alpha is 0, beta is 2147483647.
Estimation for move (2, 4) is -2147483647, alpha is 1, beta is 2147483647.
Estimation for move (5, 5) is 1, alpha is 1, beta is 2147483647.
Estimation for move (4, 2) is 1, alpha is 1, beta is 2147483647.
Estimation for move (6, 3) is 1, alpha is 1, beta is 2147483647.
Estimation for move (6, 2) is 1, alpha is 0, beta is 2147483647.
Estimation for move (5, 2) is 1, alpha is 0, beta is 2147483647.
Best move is (5, 1).
Estimation is 1.
Calculating of enemy estimation with upper bound 0. Player is Black
Starting parellel alpha beta with depth 6, player Black and beta 0.
Moves in consideration: [(2, 4), (5, 2), (6, 3), (5, 3), (3, 1), (5, 5), (6, 4), (4, 2), (1, 3), (4, 6), (4, 1), (2, 2), (3, 5)].
Estimation for move (6, 3) is 0, alpha is -1, beta is 0.
Estimation for move (2, 4) is -1, alpha is -1, beta is 0.
Best move is (6, 3).
Estimation is 0.
Estimation is greater than enemy estimation. So the best move is Some((5, 1)), estimation is 1.

thread 'minimax_test::find_best_move' panicked at 'assertion failed: `(left == right)`
  left: `Some(26)`,
 right: `Some(36)`', src/minimax_test.rs:29:2
note: Run with `RUST_BACKTRACE=1` for a backtrace.
test minimax_test::find_best_move ... FAILED

Tested on master.

$ rustc -vV
rustc 1.21.0-nightly (e26688824 2017-08-27)
binary: rustc
commit-hash: e2668882406b68739c6ed33d420358d5d710e67b
commit-date: 2017-08-27
host: x86_64-apple-darwin
release: 1.21.0-nightly
LLVM version: 4.0

Can't run bot with default parameters

Hello,

I tried to run bot via instruction in readme:

  1. cargo build --release
  2. cargo run --release -s NegaScout -t 8 -g 1000
    I've got this error:

error: The argument '--moves-order <moves-order>' cannot be used with one or more of the other specified arguments

I tried to use all combinations of Solver [UCT, NegaScout] Moves-Order [None, Random, TrajectoriesCount] parameters, but still get this error can you help me?

Thank you!

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.