Skip to content

Commit

Permalink
Merge branch 'google-deepmind:master' into fix-rcfr-for-keras-3
Browse files Browse the repository at this point in the history
  • Loading branch information
dmorrill10 authored Aug 19, 2024
2 parents b48a030 + 0be2e9a commit a31179a
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 7 deletions.
13 changes: 13 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ every two weeks (for bug fixes, it will likely be faster to be integrated). So
you may need to wait a little after it has been approved to actually see it
merged.

# OpenSpiel visual Graph

To help you understand better the framework as a whole you can go to
[openspielgraph](https://openspielgraph.netlify.app) and use an interactive
graph that shows the OpenSpiel repository in a wide and easy to undestand way.

By providing intuitive visual representations, it simplifies the debugging
process, aids in the optimization of algorithms, and fosters a more efficient
workflow.

For a practical example, see one of the reasons OpenSpielGraph was thought of
and also how to use OpenSpiel and WebAssembly...

# Roadmap and Call for Contributions

Contributions to this project must be accompanied by a Contributor License
Expand Down
3 changes: 2 additions & 1 deletion open_spiel/games/chess/chess.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ ActionsAndProbs ChessState::ChanceOutcomes() const {
}

Action ChessState::ParseMoveToAction(const std::string& move_str) const {
absl::optional<Move> move = Board().ParseMove(move_str);
bool chess960 = ParentGame()->IsChess960();
absl::optional<Move> move = Board().ParseMove(move_str, chess960);
if (!move.has_value()) {
return kInvalidAction;
}
Expand Down
5 changes: 3 additions & 2 deletions open_spiel/games/chess/chess_board.cc
Original file line number Diff line number Diff line change
Expand Up @@ -877,13 +877,14 @@ bool ChessBoard::HasSufficientMaterial() const {
return dark_bishop_exists && light_bishop_exists;
}

absl::optional<Move> ChessBoard::ParseMove(const std::string &move) const {
absl::optional<Move> ChessBoard::ParseMove(const std::string &move,
bool chess960) const {
// First see if they are in the long form -
// "anan" (eg. "e2e4") or "anana" (eg. "f7f8q")
// SAN moves will never have this form because an SAN move that starts with
// a lowercase letter must be a pawn move, and pawn moves will never require
// rank disambiguation (meaning the second character will never be a number).
auto lan_move = ParseLANMove(move);
auto lan_move = ParseLANMove(move, chess960);
if (lan_move) {
return lan_move;
}
Expand Down
3 changes: 2 additions & 1 deletion open_spiel/games/chess/chess_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ class ChessBoard {

// Parses a move in standard algebraic notation or long algebraic notation
// (see below). Returns absl::nullopt on failure.
absl::optional<Move> ParseMove(const std::string& move) const;
absl::optional<Move> ParseMove(const std::string& move,
bool chess960 = false) const;

// Parses a move in standard algebraic notation as defined by FIDE.
// https://en.wikipedia.org/wiki/Algebraic_notation_(chess).
Expand Down
6 changes: 3 additions & 3 deletions open_spiel/python/algorithms/efr.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ def return_cs_partial_sequence(num_actions, history, prior_legal_actions):
information set.
"""
prior_actions_in_memory = history
external_memory_weights = [None]
external_memory_weights = []

for i in range(len(history)):
possible_memory_weight = np.zeros(len(history))
Expand Down Expand Up @@ -851,7 +851,7 @@ def return_cs_partial_sequence_orginal(
information set.
"""
prior_actions_in_memory = history
external_memory_weights = [None]
external_memory_weights = []

for i in range(len(history)):
possible_memory_weight = np.zeros(len(history))
Expand Down Expand Up @@ -891,7 +891,7 @@ def return_twice_informed_partial_sequence(
all TIPS deviations that are realizable at theinformation set.
"""
prior_actions_in_memory = history
memory_weights = [None]
memory_weights = []

for i in range(len(history)):
possible_memory_weight = np.zeros(len(history))
Expand Down
15 changes: 15 additions & 0 deletions open_spiel/python/pybind11/python_games.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,30 @@

#include "open_spiel/python/pybind11/python_games.h"

#include <algorithm>
#include <string>
#include <memory>
#include <vector>

// Interface code for using Python Games and States from C++.

#include "open_spiel/abseil-cpp/absl/container/inlined_vector.h"
#include "open_spiel/abseil-cpp/absl/strings/escaping.h"
#include "open_spiel/abseil-cpp/absl/strings/numbers.h"
#include "open_spiel/abseil-cpp/absl/strings/str_cat.h"
#include "open_spiel/abseil-cpp/absl/strings/str_join.h"
#include "open_spiel/abseil-cpp/absl/strings/string_view.h"
#include "open_spiel/abseil-cpp/absl/strings/str_split.h"
#include "open_spiel/abseil-cpp/absl/types/optional.h"
#include "open_spiel/abseil-cpp/absl/types/span.h"
#include "open_spiel/game_parameters.h"
#include "open_spiel/python/pybind11/pybind11.h"
#include "open_spiel/observer.h"
#include "open_spiel/spiel.h"
#include "open_spiel/spiel_globals.h"
#include "open_spiel/spiel_utils.h"


namespace open_spiel {

namespace py = ::pybind11;
Expand All @@ -41,6 +51,11 @@ std::unique_ptr<State> PyGame::NewInitialState() const {
NewInitialState);
}

std::unique_ptr<State> PyGame::NewInitialState(const std::string& str) const {
PYBIND11_OVERLOAD_PURE_NAME(std::unique_ptr<State>, Game, "new_initial_state",
NewInitialState, str);
}

std::unique_ptr<State> PyGame::NewInitialStateForPopulation(
int population) const {
PYBIND11_OVERLOAD_PURE_NAME(std::unique_ptr<State>, Game,
Expand Down
9 changes: 9 additions & 0 deletions open_spiel/python/pybind11/python_games.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@
// Interface and supporting functions for defining games in Python and using
// them from C++.

#include <memory>
#include <string>
#include <vector>

#include "open_spiel/python/pybind11/pybind11.h"
#include "open_spiel/abseil-cpp/absl/types/optional.h"
#include "open_spiel/game_parameters.h"
#include "open_spiel/observer.h"
#include "open_spiel/spiel.h"
#include "open_spiel/spiel_utils.h"

namespace open_spiel {

Expand All @@ -33,6 +41,7 @@ class PyGame : public Game {

// Implementation of the Game API.
std::unique_ptr<State> NewInitialState() const override;
std::unique_ptr<State> NewInitialState(const std::string& str) const override;
std::unique_ptr<State> NewInitialStateForPopulation(
int population) const override;
int MaxChanceNodesInHistory() const override;
Expand Down

0 comments on commit a31179a

Please sign in to comment.