-
Notifications
You must be signed in to change notification settings - Fork 0
Add adversarial game search framework with Negamax and Alpha-Beta engines #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
dd0f1eb
refactor(doxyfile): Refactor Doxyfile to standardize settings
lrleon 4a4e122
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon 8863f79
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon b3b795d
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon 9e162e8
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon 95914a2
Merge branches 'master' and 'master' of github.com:lrleon/Aleph-w
lrleon a0b3061
removed not needed loop
lrleon 18097d2
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon fe7f669
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon 4d0615d
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon 82f7f17
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon ff3ccf6
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon 4cf3b3e
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon 06db919
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon 5ea000a
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon 2ee4a4c
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon e7699e1
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon 1a400ce
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon 103338f
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon a681429
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon 3c89181
Merge branch 'master' of github.com:lrleon/Aleph-w
lrleon 6c74bb6
Add state-space search framework with backtracking, branch-and-bound,…
lrleon a7c465e
feat(search): Add IDA* algorithm and move ordering
lrleon 25f7c77
refactor(core): Adjust documentation and namespaces
lrleon 7dd3e4b
refactor(core): Improve documentation comments for search engines
lrleon 3896450
refactor(core): Improve Branch and Bound search logic
lrleon 02dcd51
test(core): Add state key to domain test classes
lrleon 323aeb7
feat(search): Add IDA* state search algorithm
lrleon a5e3f30
refactor(backtracking): Improve Backtracking search APIs
lrleon 44c9261
feat(hash): Add hash_backends_test.cc
lrleon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| /* | ||
| Aleph_w | ||
|
|
||
| Data structures & Algorithms | ||
| version 2.0.0b | ||
| https://github.com/lrleon/Aleph-w | ||
|
|
||
| This file is part of Aleph-w library | ||
|
|
||
| Copyright (c) 2002-2026 Leandro Rabindranath Leon | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. | ||
| */ | ||
|
|
||
| #include <iostream> | ||
| #include <string> | ||
|
|
||
| #include <State_Search.H> | ||
|
|
||
| using namespace Aleph; | ||
|
|
||
| namespace | ||
| { | ||
|
|
||
| struct ArtificialGameState | ||
| { | ||
| size_t depth = 0; | ||
| size_t code = 1; | ||
| int player = 1; | ||
| }; | ||
|
|
||
| struct ArtificialGameMove | ||
| { | ||
| size_t next_code = 1; | ||
| char label = 'A'; | ||
| }; | ||
|
|
||
| class ArtificialGameDomain | ||
| { | ||
| public: | ||
| using State = ArtificialGameState; | ||
| using Move = ArtificialGameMove; | ||
| using Score = int; | ||
|
|
||
| bool is_terminal(const State &state) const | ||
| { | ||
| return state.depth == 2; | ||
| } | ||
|
|
||
| Score evaluate(const State &state) const | ||
| { | ||
| return root_score(state.code)*state.player; | ||
| } | ||
|
|
||
| void apply(State &state, const Move &move) const | ||
| { | ||
| state.code = move.next_code; | ||
| state.player = -state.player; | ||
| ++state.depth; | ||
| } | ||
|
|
||
| void undo(State &state, const Move&) const | ||
| { | ||
| --state.depth; | ||
| state.player = -state.player; | ||
| state.code /= 2; | ||
| } | ||
|
|
||
| template <typename Visitor> | ||
| bool for_each_successor(const State &state, Visitor visit) const | ||
| { | ||
| if (state.depth >= 2) | ||
| return true; | ||
|
|
||
| switch (state.code) | ||
| { | ||
| case 1: | ||
| if (not visit(Move{2, 'A'})) | ||
| return false; | ||
| return visit(Move{3, 'B'}); | ||
|
|
||
| case 2: | ||
| if (not visit(Move{4, 'a'})) | ||
| return false; | ||
| return visit(Move{5, 'b'}); | ||
|
|
||
| case 3: | ||
| if (not visit(Move{6, 'a'})) | ||
| return false; | ||
| return visit(Move{7, 'b'}); | ||
|
|
||
| default: | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| private: | ||
| [[nodiscard]] static Score root_score(const size_t code) noexcept | ||
| { | ||
| switch (code) | ||
| { | ||
| case 2: return 6; | ||
| case 3: return 1; | ||
| case 4: return 3; | ||
| case 5: return 5; | ||
| case 6: return 2; | ||
| case 7: return 4; | ||
| default: return 0; | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| std::string signature(const SearchPath<ArtificialGameMove> &path) | ||
| { | ||
| std::string out; | ||
| for (const auto &move : path) | ||
| out.push_back(move.label); | ||
| return out; | ||
| } | ||
|
|
||
| template <typename Result> | ||
| void print_summary(const char *title, const Result &result) | ||
| { | ||
| std::cout << title << '\n'; | ||
| std::cout << " value: " << result.value << '\n'; | ||
| std::cout << " pv: " << signature(result.principal_variation) << '\n'; | ||
| std::cout << " visited: " << result.stats.visited_states << '\n'; | ||
| std::cout << " cutoffs: " << result.stats.alpha_beta_cutoffs << '\n'; | ||
| } | ||
|
|
||
| } // end namespace | ||
|
|
||
| int main() | ||
| { | ||
| const ArtificialGameState root; | ||
|
|
||
| auto negamax = negamax_search(ArtificialGameDomain{}, root); | ||
| auto alpha_beta = alpha_beta_search(ArtificialGameDomain{}, root); | ||
|
|
||
| print_summary("Negamax", negamax); | ||
| print_summary("Alpha-Beta", alpha_beta); | ||
|
|
||
| return 0; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.