Skip to content

Commit ced1fdc

Browse files
Adding sokoban
1 parent b79abf2 commit ced1fdc

File tree

12 files changed

+393
-3
lines changed

12 files changed

+393
-3
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@
4040
[submodule "extern/quickerDSDA"]
4141
path = extern/quickerDSDA
4242
url = https://github.com/SergioMartin86/quickerDSDA.git
43+
[submodule "extern/quickerBan"]
44+
path = extern/quickerBan
45+
url = https://github.com/SergioMartin86/quickerBan.git

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ This work is based on [Jaffar](https://github.com/SergioMartin86/jaffar), a solv
3939
| Another World | [QuickerRAWGL](https://github.com/SergioMartin86/QuickerRAWGL) | Multiple | This AW interpreter works with most AW ports |
4040
| Super Mario Bros (NES) | [QuickerSMBC](https://github.com/SergioMartin86/quickerSMBC) | Bizhawk 2.9.2 | Inaccurate in transitions, but good for solving levels |
4141
| Arkanoid (NES) | [QuickerArkbot](https://github.com/SergioMartin86/quickerArkBot) | Bizhawk 2.9.2 (NesHawk Core) | |
42-
| Doom | [QuickerDSDA](https://github.com/SergioMartin86/quickerDSDA) | DSDA | Doom / Doom II |
42+
| Doom | [QuickerDSDA](https://github.com/SergioMartin86/quickerDSDA) | Doom / Doom II |
43+
| Sokoban | [QuickerBan](https://github.com/SergioMartin86/quickerBan) | Sokoban (all) |
4344

4445
Author
4546
=============

emulators/emulatorList.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
#include "quickerDSDA/quickerDSDA.hpp"
5555
#endif
5656

57+
#ifdef __JAFFAR_USE_QUICKERBAN
58+
#include "quickerBan/quickerBan.hpp"
59+
#endif
60+
5761
namespace jaffarPlus
5862
{
5963
#define DETECT_EMULATOR(EMULATOR) \
@@ -127,6 +131,10 @@ std::unique_ptr<Emulator> Emulator::getEmulator(const nlohmann::json &emulatorCo
127131
DETECT_EMULATOR(emulator::QuickerDSDA);
128132
#endif
129133

134+
#ifdef __JAFFAR_USE_QUICKERBAN
135+
DETECT_EMULATOR(emulator::QuickerBan);
136+
#endif
137+
130138
// Check if recognized
131139
if (isRecognized == false) JAFFAR_THROW_LOGIC("Emulator '%s' not recognized\n", emulatorName.c_str());
132140

emulators/meson.build

+6
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,10 @@ if emulator == 'QuickerDSDA'
8686
jaffarCPPFlags += '-D__JAFFAR_USE_QUICKERDSDA'
8787
jaffarCPPFlags += '-D__JAFFAR_ENABLE_DOOM'
8888
subdir('quickerDSDA')
89+
endif
90+
91+
if emulator == 'QuickerBan'
92+
jaffarCPPFlags += '-D__JAFFAR_USE_QUICKERBAN'
93+
jaffarCPPFlags += '-D__JAFFAR_ENABLE_SOKOBAN'
94+
subdir('quickerBan')
8995
endif

emulators/quickerBan/meson.build

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if emulator == 'QuickerBan'
2+
quickerBanSubproject = subproject('quickerBan')
3+
endif
4+
5+
# Getting QuickerBan dependency
6+
quickerBanDependency = quickerBanSubproject.get_variable('quickerBanDependency')
7+
emulatorDependencies += quickerBanDependency

emulators/quickerBan/quickerBan.hpp

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include <jaffarCommon/deserializers/base.hpp>
5+
#include <jaffarCommon/hash.hpp>
6+
#include <jaffarCommon/json.hpp>
7+
#include <jaffarCommon/logger.hpp>
8+
#include <jaffarCommon/serializers/base.hpp>
9+
#include <emulator.hpp>
10+
#include <emuInstance.hpp>
11+
12+
namespace jaffarPlus
13+
{
14+
15+
namespace emulator
16+
{
17+
18+
class QuickerBan final : public Emulator
19+
{
20+
public:
21+
22+
static std::string getName() { return "QuickerBan"; }
23+
24+
// Constructor must only do configuration parsing
25+
QuickerBan(const nlohmann::json &config)
26+
: Emulator(config)
27+
{
28+
// Creating internal emulator instance
29+
_quickerBan = std::make_unique<jaffar::EmuInstance>(config);
30+
};
31+
32+
// Function to get a reference to the input parser from the base emulator
33+
jaffar::InputParser *getInputParser() const override { return _quickerBan->getInputParser(); }
34+
35+
void initializeImpl() override
36+
{
37+
_quickerBan->initialize();
38+
}
39+
40+
jaffar::EmuInstance* getEmulator() const { return _quickerBan.get(); }
41+
42+
// State advancing function
43+
void advanceStateImpl(const jaffar::input_t &input) override { _quickerBan->advanceState(input); }
44+
45+
__INLINE__ void serializeState(jaffarCommon::serializer::Base &serializer) const override { _quickerBan->serializeState(serializer); };
46+
__INLINE__ void deserializeState(jaffarCommon::deserializer::Base &deserializer) override { _quickerBan->deserializeState(deserializer); };
47+
48+
__INLINE__ void printInfo() const override { }
49+
50+
property_t getProperty(const std::string &propertyName) const override
51+
{
52+
JAFFAR_THROW_LOGIC("Property name: '%s' not found in emulator '%s'", propertyName.c_str(), getName().c_str());
53+
}
54+
55+
void initializeVideoOutput() override {}
56+
void finalizeVideoOutput() override { }
57+
__INLINE__ void enableRendering() override { }
58+
__INLINE__ void disableRendering() override { }
59+
__INLINE__ void updateRendererState(const size_t stepIdx, const std::string input) override { }
60+
__INLINE__ void serializeRendererState(jaffarCommon::serializer::Base &serializer) const override { }
61+
__INLINE__ void deserializeRendererState(jaffarCommon::deserializer::Base &deserializer) override { }
62+
__INLINE__ size_t getRendererStateSize() const override { return 0; }
63+
64+
__INLINE__ void showRender() override
65+
{
66+
}
67+
68+
private:
69+
70+
std::unique_ptr<jaffar::EmuInstance> _quickerBan;
71+
};
72+
73+
} // namespace emulator
74+
75+
} // namespace jaffarPlus

examples/sokoban/lvl01.jaffar

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
{
2+
"Driver Configuration":
3+
{
4+
"End On First Win State": true,
5+
"Max Steps": 0,
6+
7+
"Save Intermediate Results":
8+
{
9+
"Enabled": true,
10+
"Frequency (s)": 1.0,
11+
"Best Solution Path": "/tmp/jaffar.best.sol",
12+
"Worst Solution Path": "/tmp/jaffar.worst.sol",
13+
"Best State Path": "/tmp/jaffar.best.state",
14+
"Worst State Path": "/tmp/jaffar.worst.state"
15+
}
16+
},
17+
18+
"Engine Configuration":
19+
{
20+
"State Database":
21+
{
22+
"Type": "Numa Aware",
23+
"Max Size per NUMA Domain (Mb)":
24+
[
25+
1000,
26+
1000
27+
]
28+
},
29+
30+
"Hash Database":
31+
{
32+
"Max Store Count": 2,
33+
"Max Store Size (Mb)": 10000
34+
}
35+
},
36+
37+
"Emulator Configuration":
38+
{
39+
"Emulator Name": "QuickerBan",
40+
"Input Room File": "lvl01.sok"
41+
},
42+
43+
"Runner Configuration":
44+
{
45+
"Bypass Hash Calculation": false,
46+
"Frameskip Rate": 0,
47+
"Hash Step Tolerance": 0,
48+
"Show Empty Input Slots": false,
49+
"Show Allowed Inputs": false,
50+
51+
"Store Input History":
52+
{
53+
"Enabled": true,
54+
"Max Size": 1000
55+
},
56+
57+
"Allowed Input Sets":
58+
[
59+
{
60+
"Conditions":
61+
[
62+
{ "Property": "Can Move Up", "Op": "==", "Value": true }
63+
],
64+
65+
"Inputs":
66+
[
67+
"U"
68+
],
69+
70+
"Stop Input Evaluation": false
71+
},
72+
73+
{
74+
"Conditions":
75+
[
76+
{ "Property": "Can Move Down", "Op": "==", "Value": true }
77+
],
78+
79+
"Inputs":
80+
[
81+
"D"
82+
],
83+
84+
"Stop Input Evaluation": false
85+
},
86+
87+
{
88+
"Conditions":
89+
[
90+
{ "Property": "Can Move Left", "Op": "==", "Value": true }
91+
],
92+
93+
"Inputs":
94+
[
95+
"L"
96+
],
97+
98+
"Stop Input Evaluation": false
99+
},
100+
101+
{
102+
"Conditions":
103+
[
104+
{ "Property": "Can Move Right", "Op": "==", "Value": true }
105+
],
106+
107+
"Inputs":
108+
[
109+
"R"
110+
],
111+
112+
"Stop Input Evaluation": false
113+
}
114+
],
115+
116+
"Test Candidate Inputs": false,
117+
"Candidate Input Sets": [ ]
118+
},
119+
120+
"Game Configuration":
121+
{
122+
"Game Name": "Sokoban",
123+
"Frame Rate": 60.10,
124+
"Last Input Step Reward": 0.0,
125+
126+
"Print Properties":
127+
[
128+
],
129+
130+
"Hash Properties":
131+
[
132+
],
133+
134+
"Rules":
135+
[
136+
{
137+
"Label": 1000,
138+
"Conditions":
139+
[
140+
{ "Property": "Remaining Boxes", "Op": "==", "Value": 0 }
141+
],
142+
143+
"Satisfies": [ ],
144+
145+
"Actions":
146+
[
147+
{ "Type": "Trigger Win" }
148+
]
149+
}
150+
]
151+
}
152+
}

examples/sokoban/lvl01.sok

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
###
2+
#.#
3+
# ####
4+
###$ $.#
5+
#. $@###
6+
####$#
7+
#.#
8+
###

extern/quickerBan

Submodule quickerBan added at 09dbf35

games/gameList.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
#include "doom/doom.hpp"
5252
#endif
5353

54+
#ifdef __JAFFAR_ENABLE_SOKOBAN
55+
#include "sokoban/sokoban.hpp"
56+
#endif
57+
5458
#include <emulator.hpp>
5559
#include <game.hpp>
5660
#include <jaffarCommon/json.hpp>
@@ -124,6 +128,10 @@ std::unique_ptr<Game> Game::getGame(const nlohmann::json &emulatorConfig, const
124128
DETECT_GAME(doom::Doom);
125129
#endif
126130

131+
#ifdef __JAFFAR_ENABLE_SOKOBAN
132+
DETECT_GAME(sokoban::Sokoban);
133+
#endif
134+
127135
// Check if game was recognized
128136
if (isRecognized == false) JAFFAR_THROW_LOGIC("Game '%s' not recognized\n", gameName.c_str());
129137

0 commit comments

Comments
 (0)