Giter Site home page Giter Site logo

pazulove's Introduction

🍜 パズそば・スーパー

Github Actions License Issues

Puzzle & Dragons is a mobile game developed by GungHo Online Entertainment,Inc. In this game, there is a board and you can erase orbs to make combos and damage dungeon monsters. Every combo will increase your attack by 25%. Also, there are skyfall orbs that might potentially make more combos.

Some demo on YouTube mostly in Japanese.

Projects

The goal

There are 30 * 3 ^ 25 possible states for a 6 x 5 board (with max steps of 25) so it is impossible to find the true optimal path. Therefore, the goal is to find a good path quickly. Ideally, it should be short, cascading and aiming for the max combo (except that it is never that ideal).

Show more information

My approach

A priority queue is used which limits the size to a fixed number and only states with a better score can be inserted to the queue. Thus, this is a very greedy approach and it is callled BEAM SEARCH. Overall, it has surpassed many pro players but it is not perfect. I will keep making it better over times.

Show more

Why beam search

Greedy DFS -> Greedy B(best)FS -> My special greedy BFS -> Beam Search

As you can see, they are all greedy algorithms based on a heuristic. The reason is that the end goal is unknown and there are also negative values. Simply choosing the local maxima may result in poor solutions.

Best first search improves the overall performance but it consumes too much memory and is extremely slow in computation. That's why I wanted to prune useless branches because a better path is guaranteed to have a better score.

My special BFS was thus introduced. It can be seen as my attempt on the Beam Search algorithm but it has a problem, shortsighted. With size 1000, it can only check 6 steps (3^6) and after that, it only inserts if a state is better than the current best state. However, states with more potential might be blocked by local maxima because currently, it has less score.

Introducing beam search, it checks more states compared to my special BFS and accepts states with a lower score. For a beam size of 1000, it always checks for 3000 states per step and chooses the best 1000 and continue with the next step. It is not optimal but often, really close. This algorithm makes the complexity from 30 _ 3 ^ 25 to 25 _ 1000 * 3 (step 25, size 1000 and no diagonal moves).

Now, with compiler optimisation and multi-threading, it runs quite fast. On my main desktop, it is even faster than padopt due to multi-threading. I am certain that with a better eraseOrb() function, pazusoba can be even faster.

Improvements

  • Safe thread
  • Better heuristic for OrbProfile and VoidPenProfile
  • Prevent a cycle especially when the step is more than 60
  • Better queue and loop

Many improvements have been done so far. Thread is causing some issues and some profiles can be better (they are worse than me and that's not acceptable). There are many duplicate board what should I do about it? If size 20000 only takes about 3s or less, it would be amazing.

Profiles

There are many playstyles in Puzzle & Dragons and profile is just for that. Now, it supports combo, colour, shape and orb based profiles.

  • Combo focuses on doing more combo with cascading and skyfall (this is the best so far)
  • Colour focuses on erasing more kinds of orbs (ideally, it should have a weight)
  • Shape encourages a certain shape (2U, +, L, one row, void damage pen)
  • Orb encourages to have less orbs remaining (this one doesn't work that well)

You can mix everything together and use for many teams.

Show all profiles
  • ComboProfile
  • ColourProfile
  • ShapeProfile
    • TwoWayProfile
    • LProfile
    • PlusProfile
    • VoidPenProfile (doesn't work at the moment)
    • SoybeanProfile
    • OneRowProfile
  • OrbProfile (not good enough)

It is quite simple to add more profiles so feel free to fork this repo and add even more profiles.

How to compile

This project was originally developed on Windows 10 with MinGW. Later, I also tried on Mac OS and Linux. Now, I am using CMake to make it easier to build across all three platforms.

Setup

On Windows, MinGW is recommened as this is what I am using. MCVS is also supported but remember to add --config when building. On Mac OS and Linux, g++/clang++ is preferred. Xcode also works on Mac OS.

Requirements

  • CMake (3.10+)
  • MinGW/g++/clang++ with C++17 support
    • C++11 is the minimum requirement as lambda is used
    • Nested namespace requires C++17 but can be easily updated

Setup CMake

cmake -B release
cd release
make pazusoba_binary
./pazusoba_binary.exe

Add -DCMAKE_BUILD_TYPE=Debug to debug or test pazusoba.

cmake -B debug -G -DCMAKE_BUILD_TYPE=Debug
cd debug
make test_pazusoba
./test_pazusoba.exe

Alternatively, you can use make.py.

Build

On Windows, it is recommened to use -G "MinGW Makefiles" instead of MSVC. On Mac OS and Linux, simply use the default. Go to the debug or release folder and run make [target].

The program accepts 4 arguments for now (more might be added later)

  • Path to the board / board string
  • Minimum erase condition (by default 3)
  • Max step (by default 50)
  • Max beam size (by default 5000)
$ ./a.out GLHLGGLBDHDDDHGHHRDRLDDLGLDDRG 3 25 1000
$ ./a.out assets/sample_board_65.txt 3

By increasing the beam size, it will take more time (linear space) to compute. With more CPU cores, it runs significantly faster.

Benchmark

Binaries are compiled locally and overall time are used based on the same board, max step 50 and beam size 5000. This might not be accurate. Use it as a reference.

Version A12Z Bionic i5-9400 Note
0.1α 213.54s 110.34s Proof of Concept
0.2α 92.46s 39.97s General Improvement
0.3α 12.06s 10.51s Compiler Optimisation
0.4α 2.79s 2.15s Multi-Threading
0.5α 3.06s 1.79s Profile & OpenCV
0.6β 3.35s 2.04s Automation
0.7.1β 1.71s 0.91s General Improvement
0.7.5β - - Full Automation
0.8γ - 0.77s Rework

Resources

Things that were helpful during my experiments.

tnkt37さん's video really inspired me and it was the reason why I started this project.

License

Legacy Code

They have been removed now. Check here if needed.

Miscellaneous

Miscellaneous

2000 days

I have been playing this game (the Japanese version) for more than 2000 days (until 2/7/2020). I started playing in 2013 and it was also when I started programming and learning the Japanese language. Lots of great memories back then with my Japanese friend. C++ reminds me of my good old days with C programming. You feel like you can do anything with it. C is special because it was my first programming language but it was a tough way to start programming, lol. Lately, I have been using JS, Python, Dart, Swift and Kotlin. They are modern, nice and easier to write but it is nice to stop and go back to the origin once a while. 2000日たまドラ たま~ たま~

pazulove's People

Contributors

henryquan avatar

Watchers

 avatar

pazulove's Issues

Discussion with Davis

  • Data Generation
    • input
    • output
  • Neural Network (input, hidden layers config & output)
  • Bootstrapping Data Augmentation
    • Use the same data multiple times (10 - 100 times)

Now, I need to implement pazusoba again. I wonder how long it takes to get the score for one data... Hopefully, it won't take a month. It shouldn't, right?

Issues with the neural network

It doesn't work but I don't really know why... The model setup might be wrong (hidden layers). Data might be wrong (normalisation). The algorithm I use might be wrong. There are so many reasons why it doesn't work. I will wait for my op senpai :)

Collect data from pazusoba

Pazusoba gets real boards instead of randomly generated ones. It might be a good idea to add a new method to write to a CSV file. This might be useful in the future for score estimation.

Rework

Normalisation is probably needed. The reason why it didn't work is probably because there are too many different configurations. I should probably normalise it to numbers and start from 0 ends with 5 instead of letters. I will have a try again.

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.