lucidtaz / minimax Goto Github PK
View Code? Open in Web Editor NEWMiniMax engine for game decision making
License: MIT License
MiniMax engine for game decision making
License: MIT License
See tip number 7 on https://blog.martinhujer.cz/17-tips-for-using-composer-efficiently/
Currently GameState
knows about Decision
and vice versa. This is not really good design and should be eliminated. When solved, it will make the program easier to reason about. Also, it doesn't force a bad practice onto interface implementers.
GameState
's knowledge lies in GameState::getDecisions(): Decision[]
and Decision
's knowledge lies in Decision::apply(GameState): GameState
.
One possible solution is to move apply
from Decision
to GameState
. It could also help to think about extracting a Board
class from GameState
and making only that known to Decision
. However, care should be taken to keep the interface as simple as needed.
There are at least three logical optimizations possible, which should be implemented in order to 1) search a broader space (more game support), or 2) be able to search deeper (harder difficulty).
The optimizations are:
The Decision
interface prescribes an apply method receiving a GameState
parameter, which is itself also an interface. This makes sense from an interface standpoint, but it constrains an implementer that applies strict static analysis.
The reason is that a concrete MyDecision
wants a concrete MyGameState
as a parameter, in order to actually do something useful such as filling a field on the board. However, since the interface prescribes a GameState
parameter, this is not possible without agitating static analysis tools. (Such as phpstan with a high enough strictness level.)
Conceptually this could be solved by templating in languages that support it. In PHP however we need to look to other solutions. Perhaps a concrete Decision
can already take its original concrete GameState
via the constructor so that the interface does not need to know about it? Since Decisions
are constructed by concrete GameStates
, this keeps all concreteness at the implementer's side.
The code could become a lot cleaner by extracting a Board
class from the TicTacToe example GameState
class. The example will be easier to understand, and it might even have a positive impact on the tests readability.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.