Skip to content

Commit

Permalink
Merge tag 'Reversi2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nugnikoll committed Jun 22, 2018
2 parents 6155ed6 + 0688a8a commit 9e62ff6
Show file tree
Hide file tree
Showing 81 changed files with 13,250 additions and 1,808 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
out*
*temp*

data/data.cc
!data/pattern.dat

*.dot
optimize/*.png
optimize/*/*.png
Expand Down
50 changes: 27 additions & 23 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,75 +6,79 @@
### Overview
Reversi (also called Othello) is a kind of strategy board game which involves play by two parties on an eight-by-eight square grid. For details of reversi please go to [https://en.wikipedia.org/wiki/Reversi](https://en.wikipedia.org/wiki/Reversi).

This reversi project is my simple work. The kernel is written in C++11 whith a bit inline assembly. Script language python and tcl can be embeded to ease the interaction with users. The GUI is built with wxwidgets. It can be written in C++ or python. The sources of this project can be merged in to a single file and submitted to [Botzone](https://botzone.org) which is a online platform for competetion of differnt bots made by students and other programming learners.
This reversi project is my simple work. The kernel is written in C++11 whith a bit inline assembly. Script language Python and TCL can be embeded to ease the interaction with users. The GUI is built with wxwidgets. It can be written in C++ or python. The sources of this project can be merged in to a single file and submitted to [Botzone](https://botzone.org) which is a online platform for competition of differnt bots made by students and other programming learners.

### Build reversi

- Prerequisites
- Essential
- gcc compiler
C++11 must be supported by this version of gcc. It cannot be compiled by Visual Studio as MS compiler supports neither 64-bit inline assembly nor AT&T flavor syntax. I'm not sure whether other compilers like Clang++ works or not.
- A decent C++ compiler
C++11 must be supported by this version of compiler. The project will not use inline assembly when compiled by Visual Studio as MS compiler supports neither 64-bit inline assembly nor AT&T flavor syntax.
- Optional
- CodeBlocks or Cbp2make (if you want to utilize the .cbp codeblocks project file to build this project)
- TCL (if you want to embed tool command language)
- cpptcl (if you want to embed tool command language)
- Boost (required by cpptcl)
- wxWidgets (required by the GUI version written in C++)
- python3 (required by the GUI version written in Python and some simple scripts)
- python (required by the GUI version written in Python and some simple scripts)
- swig (required by the GUI version written in Python)
- wxPython (required by the GUI version written in Python)

Personally, I've only built the project on 64-bit windows and cygwin but I believe it can migrates to other platforms.
Personally, I've only built the project on 64-bit windows and cygwin but I believe it can migrate to other platforms.

- Build reversi with only basic functions
1. Install latest version of gcc.
2. Create a C++ project.
3. Add following files to your project.
type.h type.cc reversi.h reversi.cc flip.cc search.h search.cc pattern.h pattern.cc (game.h game.cc)
4. Write your main.cc source file with "reversi.h" ("game.h") included.
5. Compile it.

- Build reversi which can be executed on [Botzone](https://botzone.org)
1. Open reversi_json.cbp with CodeBlocks or use cbp2make.exe to generate makefile on your own platform.
2. Compile it.

To submit it to Botzone, several sources have to be merged into a single file. If you have python installed, run the script ./single/merge.py and main_merge.cc will be generated automatically.

- Build reversi with tcl embeded
1. Install latest version of gcc, TCL, Boost. Download cpptcl.
1. Install TCL, Boost. Download cpptcl.
2. Open reversi.cbp with CodeBlocks or use cbp2make.exe to generate makefile on your own platform.
3. Change the paths of libraries.
4. Compile it.

- Build reversi GUI version with tcl embeded
1. Install latest version of gcc, TCL, Boost, wxwidgets. Download cpptcl.
1. Install TCL, Boost, wxwidgets. Download cpptcl.
2. Open reversi_gui.cbp with CodeBlocks or use cbp2make.exe to generate makefile on your own platform.
3. Change the paths of libraries.
4. Compile it.

- Build reversi python GUI version (apparently there's no need to embed tcl anymore)
1. Install latest version of gcc, python3, swig, wxpython.
1. Install python, swig, wxpython.
2. Run cmd/shell.
3. Enter the directory $(REVERSI_PROJECT)/python/
4. Type following command.
`swig -python -c++ -threads reversi_wrap.cxx`
`python3 setup.py build_ext --inplace --compiler=mingw32`
Note: `--compiler=mingw32` has to changed according to your compiler.
`swig -python -c++ -threads reversi.i`
`python setup.py build_ext --inplace --compiler=mingw32`
Note: `--compiler=mingw32` has to be changed according to your compiler.
If it's built successfully, dynamic link library _reversi.pyd or _reversi.dll or _reversi.so should be generated and main.py can be executed.

### Development

class board
│ flip()
│ search()
reversi.h: class board
│ board::flip()
│ board::score()
│ board::search()
│ ...
└───class game
└───game.h: class game
│ │
│ └───reversi_tcl
│ └───reversi_tcl.h
│ │ │
│ │ └───main.cc (C++ tcl console project)
│ │ │
│ │ └───reversi_gui
│ │ └───reversi_gui.h: class game_gui
│ │ │
│ │ └───reversi_guiFrame (C++ tcl GUI project)
│ │ └───reversi_guiMain.h: class reversi_guiFrame (C++ tcl GUI project)
│ │
│ └───reversi_gui.py
│ └───reversi_gui.py: class game_gui
│ │
│ └───main.py (python GUI project)
└───main_json (Botzone online project)
└───main_json.cc (Botzone online project)
56 changes: 56 additions & 0 deletions asm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/** @file asm.h
* @brief This file includes some macros for inline assembly.
*/

#ifndef ASM_H
#define ASM_H

#define asm_rol(brd,val) \
asm volatile( \
"rol %1, %0;" \
: "+r"(brd) \
: "c"(char(val)) \
)

#define asm_ror(brd,val) \
asm volatile( \
"ror %1, %0;" \
: "+r"(brd) \
: "c"(char(val)) \
)

#define asm_bswap(brd) \
asm volatile( \
"bswap %0;" \
: "+r"(brd) \
)

#define asm_popcnt(brd,result) \
asm volatile( \
"popcnt %1, %0;" \
: "=r"(result) \
: "r"(brd) \
)

#define asm_tzcnt(brd,result) \
asm volatile( \
"tzcnt %1, %0;" \
:"=r"(result) \
:"r"(brd) \
)

#define asm_pext(brd, mask, result) \
asm volatile( \
"pext %1, %2, %0;" \
: "=r"(result) \
: "r"(mask), "r"(brd) \
)

#define asm_pdep(brd, mask, result) \
asm volatile( \
"pdep %1, %2, %0;" \
: "=r"(result) \
: "r"(mask), "r"(brd) \
)

#endif //ASM_H
22 changes: 11 additions & 11 deletions cpptcl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
using namespace Tcl;
using namespace Tcl::details;
using namespace std;
using namespace boost;
using namespace std;

result::result(Tcl_Interp *interp) : interp_(interp) {}

Expand Down Expand Up @@ -278,7 +278,7 @@ int callback_handler(ClientData, Tcl_Interp *interp,
if (it == callbacks.end())
{
Tcl_SetResult(interp,
"Trying to invoke non-existent callback (wrong interpreter?)",
const_cast<char*>("Trying to invoke non-existent callback (wrong interpreter?)"),
TCL_STATIC);
return TCL_ERROR;
}
Expand All @@ -288,7 +288,7 @@ int callback_handler(ClientData, Tcl_Interp *interp,
if (iti == it->second.end())
{
Tcl_SetResult(interp,
"Trying to invoke non-existent callback (wrong cmd name?)",
const_cast<char*>("Trying to invoke non-existent callback (wrong cmd name?)"),
TCL_STATIC);
return TCL_ERROR;
}
Expand All @@ -297,7 +297,7 @@ int callback_handler(ClientData, Tcl_Interp *interp,
if (pit == call_policies.end())
{
Tcl_SetResult(interp,
"Trying to invoke callback with no known policies",
const_cast<char*>("Trying to invoke callback with no known policies"),
TCL_STATIC);
return TCL_ERROR;
}
Expand All @@ -306,7 +306,7 @@ int callback_handler(ClientData, Tcl_Interp *interp,
if (find_policies(interp, cmdName, piti) == false)
{
Tcl_SetResult(interp,
"Trying to invoke callback with no known policies",
const_cast<char*>("Trying to invoke callback with no known policies"),
TCL_STATIC);
return TCL_ERROR;
}
Expand All @@ -326,7 +326,7 @@ int callback_handler(ClientData, Tcl_Interp *interp,
}
catch (...)
{
Tcl_SetResult(interp, "Unknown error.", TCL_STATIC);
Tcl_SetResult(interp, const_cast<char*>("Unknown error."), TCL_STATIC);
return TCL_ERROR;
}

Expand Down Expand Up @@ -369,7 +369,7 @@ int object_handler(ClientData cd, Tcl_Interp *interp,
}
catch (...)
{
Tcl_SetResult(interp, "Unknown error.", TCL_STATIC);
Tcl_SetResult(interp, const_cast<char*>("Unknown error."), TCL_STATIC);
return TCL_ERROR;
}

Expand All @@ -391,7 +391,7 @@ int constructor_handler(ClientData cd, Tcl_Interp *interp,
if (it == constructors.end())
{
Tcl_SetResult(interp,
"Trying to invoke non-existent callback (wrong interpreter?)",
const_cast<char*>("Trying to invoke non-existent callback (wrong interpreter?)"),
TCL_STATIC);
return TCL_ERROR;
}
Expand All @@ -401,7 +401,7 @@ int constructor_handler(ClientData cd, Tcl_Interp *interp,
if (iti == it->second.end())
{
Tcl_SetResult(interp,
"Trying to invoke non-existent callback (wrong class name?)",
const_cast<char*>("Trying to invoke non-existent callback (wrong class name?)"),
TCL_STATIC);
return TCL_ERROR;
}
Expand All @@ -410,7 +410,7 @@ int constructor_handler(ClientData cd, Tcl_Interp *interp,
if (find_policies(interp, className, piti) == false)
{
Tcl_SetResult(interp,
"Trying to invoke callback with no known policies",
const_cast<char*>("Trying to invoke callback with no known policies"),
TCL_STATIC);
return TCL_ERROR;
}
Expand All @@ -436,7 +436,7 @@ int constructor_handler(ClientData cd, Tcl_Interp *interp,
}
catch (...)
{
Tcl_SetResult(interp, "Unknown error.", TCL_STATIC);
Tcl_SetResult(interp, const_cast<char*>("Unknown error."), TCL_STATIC);
return TCL_ERROR;
}

Expand Down
Loading

0 comments on commit 9e62ff6

Please sign in to comment.