Skip to content
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

Adding game german_whist_foregame #1171

Merged
merged 31 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f717bf6
Create german_whist_foregame
willmcgowan Nov 12, 2023
11096d0
Delete open_spiel/games/german_whist_foregame
willmcgowan Nov 12, 2023
8485343
Create german_whist_foregame.cc
willmcgowan Nov 12, 2023
397489a
Create german_whist_foregame.h
willmcgowan Nov 12, 2023
9851a65
Create solver.cc
willmcgowan Nov 12, 2023
8b2aea9
Create german_whist_foregame_test.cc
willmcgowan Nov 12, 2023
5ac7efe
Beginning
willmcgowan Nov 13, 2023
f1ce917
Majority of changes
willmcgowan Jan 27, 2024
f9c9561
DONEEEE
willmcgowan Jan 27, 2024
b29507a
Modified TTable datastructure
willmcgowan Jan 28, 2024
927e1f6
Update spiel.h
willmcgowan Jan 28, 2024
6095750
Update basic_tests.cc
willmcgowan Jan 28, 2024
3f3183c
Small clean up
willmcgowan Jan 28, 2024
7678158
More cleanup
willmcgowan Jan 28, 2024
5484fa9
set kTTablePath to empty string
willmcgowan Jan 28, 2024
3184a10
Modified all intrinsics to generics
willmcgowan Jan 29, 2024
aee203b
added game name to pyspiel test
willmcgowan Jan 29, 2024
51d92b0
Code cleanup/speedup
willmcgowan Jan 30, 2024
c7b337a
Bithack modification & LoadTTable warning
willmcgowan Jan 30, 2024
a53bb57
Removed attempt to add compile with BMI2
willmcgowan Jan 30, 2024
20ecb71
Removing text
willmcgowan Jan 30, 2024
931113a
Update pyspiel_test.py
willmcgowan Feb 18, 2024
6727aee
Update german_whist_foregame.cc
willmcgowan Feb 18, 2024
a705df1
Changes to pass integration testss
willmcgowan Mar 7, 2024
4a367d8
missing comma
willmcgowan Mar 7, 2024
c65002d
Formatting
willmcgowan Mar 8, 2024
5e02ea0
LINTING
willmcgowan Mar 8, 2024
4cd3016
Fixed const correctness
willmcgowan Mar 8, 2024
b3032e5
Using Approved Headers
willmcgowan Jul 2, 2024
b3490d0
removed std::thread dependency
willmcgowan Aug 6, 2024
192c9f6
Semicolon
willmcgowan Aug 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion open_spiel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if(${BUILD_TYPE} STREQUAL "Testing")
# A build used for running tests: keep all runtime checks (assert,
# SPIEL_CHECK_*, SPIEL_DCHECK_*), but turn on some speed optimizations,
# otherwise tests run for too long.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 ")
endif()

if(${BUILD_TYPE} STREQUAL "Release")
Expand Down Expand Up @@ -295,6 +295,7 @@ if (OPEN_SPIEL_BUILD_WITH_TENSORFLOW_CC)
find_package(TensorflowCC REQUIRED)
endif()


# We have the parent of this directory in the include path, so that we can
# include for example "open_spiel/spiel.h" (assuming this directory is named
# open_spiel).
Expand Down
2 changes: 2 additions & 0 deletions open_spiel/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ add_executable(fsicfr_liars_dice fsicfr_liars_dice.cc ${OPEN_SPIEL_OBJECTS})

add_executable(gtp gtp.cc ${OPEN_SPIEL_OBJECTS})

add_executable(is_mcts_gwhist is_mcts_gwhist.cc ${OPEN_SPIEL_OBJECTS})

add_executable(matrix_example matrix_example.cc ${OPEN_SPIEL_OBJECTS})
add_test(matrix_example_test matrix_example)

Expand Down
81 changes: 81 additions & 0 deletions open_spiel/examples/is_mcts_gwhist.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2021 DeepMind Technologies Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "open_spiel/algorithms/is_mcts.h"

#include <random>

#include "open_spiel/abseil-cpp/absl/random/distributions.h"
#include "open_spiel/algorithms/mcts.h"
#include "open_spiel/spiel.h"
#include "open_spiel/spiel_bots.h"
#include "open_spiel/spiel_utils.h"

namespace open_spiel {
namespace {

constexpr const int kSeed = 9492110;//93879211;

void PlayGWhist(int human_player, std::mt19937* rng) {
std::shared_ptr<const Game> game = LoadGame("german_whist_foregame");
std::random_device rd;
int eval_seed = rd();
int bot_seed = rd();
auto evaluator = std::make_shared<algorithms::RandomRolloutEvaluator>(1, eval_seed);
auto bot = std::make_unique<algorithms::ISMCTSBot>(
bot_seed, evaluator, 0.7, 500000, algorithms::kUnlimitedNumWorldSamples,
algorithms::ISMCTSFinalPolicyType::kMaxVisitCount,true, false);
std::unique_ptr<State> state = game->NewInitialState();
while (!state->IsTerminal()) {

Action chosen_action = kInvalidAction;
if (state->IsChanceNode()) {
chosen_action =
SampleAction(state->ChanceOutcomes(), absl::Uniform(*rng, 0.0, 1.0))
.first;
} else if(state->CurrentPlayer()!=human_player) {
chosen_action = bot->Step(*state);
}
else{
std::cout<<state->InformationStateString(human_player)<<std::endl;
auto legal_actions = state->LegalActions();
for(int i =0;i<legal_actions.size();++i){
std::cout<<state->ActionToString(legal_actions[i])<<",";
}
std::cout<<std::endl;
std::cout<<"Input action:";
std::string input;
std::cin>>input;
chosen_action = state->StringToAction(input);
std::cout<<std::endl;
}
state->ApplyAction(chosen_action);
}

std::cout << "Terminal state:" << std::endl;
std::cout << state->ToString() << std::endl;
std::cout << "Returns: " << absl::StrJoin(state->Returns(), " ") << std::endl;
}


} // namespace
} // namespace open_spiel



int main(int argc, char** argv) {
std::random_device rd;
std::mt19937 rng(rd());
open_spiel::PlayGWhist(0,&rng);
}
8 changes: 8 additions & 0 deletions open_spiel/games/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ set(GAME_SOURCES
euchre/euchre.h
first_sealed_auction/first_sealed_auction.cc
first_sealed_auction/first_sealed_auction.h
german_whist_foregame/german_whist_foregame.cc
german_whist_foregame/german_whist_foregame.h
gin_rummy/gin_rummy.cc
gin_rummy/gin_rummy.h
gin_rummy/gin_rummy_utils.cc
Expand Down Expand Up @@ -192,6 +194,7 @@ if (${OPEN_SPIEL_BUILD_WITH_ACPC})
set(GAME_SOURCES ${GAME_SOURCES} universal_poker/universal_poker.cc universal_poker/universal_poker.h)
endif()


add_library (games OBJECT ${GAME_SOURCES})

target_include_directories (games PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
Expand Down Expand Up @@ -428,6 +431,11 @@ add_executable(garnet_test mfg/garnet_test.cc ${OPEN_SPIEL_OBJECTS}
$<TARGET_OBJECTS:tests>)
add_test(garnet_test garnet_test)

add_executable(german_whist_foregame_test german_whist_foregame/german_whist_foregame_test.cc ${OPEN_SPIEL_OBJECTS}
$<TARGET_OBJECTS:tests>)
add_test(german_whist_foregame_test german_whist_foregame_test)
add_executable(german_whist_endgame german_whist_foregame/german_whist_endgame.cc ${OPEN_SPIEL_OBJECTS})

add_executable(gin_rummy_test gin_rummy/gin_rummy_test.cc ${OPEN_SPIEL_OBJECTS}
$<TARGET_OBJECTS:tests>)
add_test(gin_rummy_test gin_rummy_test)
Expand Down
Loading
Loading