1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 11:37:45 +00:00

2048: Evil AI logic: select new tile in the worst position

Not very smart: the worst position is defined such that after the
player's next move the fewest tiles remain empty.
This commit is contained in:
Dmitrii Ubskii 2021-05-15 17:37:29 +03:00 committed by Linus Groh
parent 4434e900af
commit a93d0fe8c2
3 changed files with 83 additions and 7 deletions

View file

@ -10,8 +10,9 @@
class Game final {
public:
Game(size_t board_size, size_t target_tile = 0);
Game(size_t grid_size, size_t target_tile, bool evil_ai);
Game(const Game&) = default;
Game& operator=(const Game&) = default;
enum class MoveOutcome {
OK,
@ -49,11 +50,22 @@ public:
private:
bool slide_tiles(Direction);
void add_tile()
{
if (m_evil_ai)
add_evil_tile();
else
add_random_tile();
}
void add_random_tile();
void add_evil_tile();
size_t m_grid_size { 0 };
u32 m_target_tile { 0 };
bool m_evil_ai { false };
Board m_board;
size_t m_score { 0 };
size_t m_turns { 0 };