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

Improve Windows compatibility #1255

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion docs/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ CMake, and choose `C:\Users\MyUser\open_spiel\open_spiel\CMakeLists.txt`. CMake
will then run; once you see `CMake generation finished`, choose Build -> Build
All. The files will be available in
`C:\Users\MyUser\open_spiel\open_spiel\out\build\x64-Debug`, when the build
completes with "Build All succeeded."
completes with "Build All succeeded."
Extra compilation options may be necessary if errors occur.
MSVC options to deal with required C++ standard, file encoding (for chess characters) and large object files include `/std:c++17`, `/utf-8`, `/bigobj`.
To use them together with default MSVC arguments, you can use the follwing CMake command line arguments:
```
-DCMAKE_CXX_FLAGS="/std:c++17 /utf-8 /bigobj /DWIN32 /D_WINDOWS /GR /EHsc"
```

To be able to import the Python code (both the C++ binding `pyspiel` and the
rest) from any location, you will need to add to your PYTHONPATH the root
Expand Down
2 changes: 1 addition & 1 deletion open_spiel/games/bridge/bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// 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.

#define NOMINMAX
#include "open_spiel/games/bridge/bridge.h"

#include <algorithm>
Expand Down
34 changes: 17 additions & 17 deletions open_spiel/games/twixt/twixtboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ void Board::AppendPegChar(std::string& s, Position position) const {
void Board::AppendBeforeRow(std::string& s, Position position) const {
// -1, +1
int len = s.length();
AppendLinkChar(s, position + (Position){-1, 0}, kENE, "/");
AppendLinkChar(s, position + (Position){-1, -1}, kNNE, "/");
AppendLinkChar(s, position + (Position){0, 0}, kWNW, "_");
AppendLinkChar(s, position + Position{-1, 0}, kENE, "/");
AppendLinkChar(s, position + Position{-1, -1}, kNNE, "/");
AppendLinkChar(s, position + Position{0, 0}, kWNW, "_");
if (len == s.length()) s.append(" ");

// 0, +1
Expand All @@ -399,48 +399,48 @@ void Board::AppendBeforeRow(std::string& s, Position position) const {

// +1, +1
len = s.length();
AppendLinkChar(s, position + (Position){+1, 0}, kWNW, "\\");
AppendLinkChar(s, position + (Position){+1, -1}, kNNW, "\\");
AppendLinkChar(s, position + (Position){0, 0}, kENE, "_");
AppendLinkChar(s, position + Position{+1, 0}, kWNW, "\\");
AppendLinkChar(s, position + Position{+1, -1}, kNNW, "\\");
AppendLinkChar(s, position + Position{0, 0}, kENE, "_");
if (len == s.length()) s.append(" ");
}

void Board::AppendPegRow(std::string& s, Position position) const {
// -1, 0
int len = s.length();
AppendLinkChar(s, position + (Position){-1, -1}, kNNE, "|");
AppendLinkChar(s, position + (Position){0, 0}, kWSW, "_");
AppendLinkChar(s, position + Position{-1, -1}, kNNE, "|");
AppendLinkChar(s, position + Position{0, 0}, kWSW, "_");
if (len == s.length()) s.append(" ");

// 0, 0
AppendPegChar(s, position);

// +1, 0
len = s.length();
AppendLinkChar(s, position + (Position){+1, -1}, kNNW, "|");
AppendLinkChar(s, position + (Position){0, 0}, kESE, "_");
AppendLinkChar(s, position + Position{+1, -1}, kNNW, "|");
AppendLinkChar(s, position + Position{0, 0}, kESE, "_");
if (len == s.length()) s.append(" ");
}

void Board::AppendAfterRow(std::string& s, Position position) const {
// -1, -1
int len = s.length();
AppendLinkChar(s, position + (Position){+1, -1}, kWNW, "\\");
AppendLinkChar(s, position + (Position){0, -1}, kNNW, "\\");
AppendLinkChar(s, position + Position{+1, -1}, kWNW, "\\");
AppendLinkChar(s, position + Position{0, -1}, kNNW, "\\");
if (len == s.length()) s.append(" ");

// 0, -1
len = s.length();
AppendLinkChar(s, position + (Position){-1, -1}, kENE, "_");
AppendLinkChar(s, position + (Position){+1, -1}, kWNW, "_");
AppendLinkChar(s, position + Position{-1, -1}, kENE, "_");
AppendLinkChar(s, position + Position{+1, -1}, kWNW, "_");
AppendLinkChar(s, position, kSSW, "|");
if (len == s.length()) AppendLinkChar(s, position, kSSE, "|");
if (len == s.length()) s.append(" ");

// -1, -1
len = s.length();
AppendLinkChar(s, position + (Position){-1, -1}, kENE, "/");
AppendLinkChar(s, position + (Position){0, -1}, kNNE, "/");
AppendLinkChar(s, position + Position{-1, -1}, kENE, "/");
AppendLinkChar(s, position + Position{0, -1}, kNNE, "/");
if (len == s.length()) s.append(" ");
}

Expand Down Expand Up @@ -514,7 +514,7 @@ void Board::SetPegAndLinks(Player player, Position position) {
if (target_cell.color() == cell.color()) {
// check if there are blocking links before setting link
const std::set<Link>& blockers =
BlockerMap::GetBlockers((Link){position, dir});
BlockerMap::GetBlockers(Link{position, dir});
bool blocked = false;
for (auto& bl : blockers) {
if (GetCell(bl.position).HasLink(bl.direction)) {
Expand Down
7 changes: 6 additions & 1 deletion open_spiel/utils/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,15 @@ bool Exists(const std::string& path) {
}

std::string RealPath(const std::string& path) {
#ifdef _WIN32
char real_path[MAX_PATH];
if (_fullpath(real_path, path.c_str(), MAX_PATH) == nullptr) {
#else
char real_path[PATH_MAX];
if (realpath(path.c_str(), real_path) == nullptr) {
// If there was an error return an empty path
return "";
#endif
return "";
}

return std::string(real_path);
Expand Down
Loading