Skip to content

Commit

Permalink
Merge pull request #1 from tewalds/master
Browse files Browse the repository at this point in the history
update from latest timo version
  • Loading branch information
ryanbhayward committed Feb 17, 2015
2 parents 6a427cb + aa13d2c commit 1632e35
Show file tree
Hide file tree
Showing 224 changed files with 15,105 additions and 20,788 deletions.
13 changes: 3 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@
*.o

# executables
castro
castro-*
chex
chex-*
moy
moy-*
pentagod
pentagod-*
trex
trex-*
morat-*
test
test-*

# valgrind output
callgrind.out.*
Expand Down
84 changes: 70 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,83 +25,139 @@ else
endif


all: castro chex moy trex pentagod
all: morat-havannah morat-hex morat-pentago morat-rex morat-y

castro: \
havannah/castro.o \
test: \
lib/test.o \
lib/fileio.o \
lib/move_test.o \
lib/outcome.o \
lib/outcome_test.o \
lib/sgf_test.o \
lib/string.o \
lib/string_test.o \
lib/zobrist.o \
havannah/agentmcts.o \
havannah/agentmctsthread.o \
havannah/agentmcts_test.o \
havannah/agentpns.o \
havannah/agentpns_test.o \
havannah/board.o \
havannah/board_test.o \
hex/agentmcts.o \
hex/agentmctsthread.o \
hex/agentmcts_test.o \
hex/agentpns.o \
hex/agentpns_test.o \
hex/board.o \
hex/board_test.o \
pentago/agentmcts.o \
pentago/agentmctsthread.o \
pentago/agentmcts_test.o \
pentago/agentpns.o \
pentago/agentpns_test.o \
pentago/board.o \
rex/agentmcts.o \
rex/agentmctsthread.o \
rex/agentmcts_test.o \
rex/agentpns.o \
rex/agentpns_test.o \
rex/board.o \
rex/board_test.o \
y/agentmcts.o \
y/agentmctsthread.o \
y/agentmcts_test.o \
y/agentpns.o \
y/agentpns_test.o \
y/board.o \
y/board_test.o \
$(ALARM)
$(CXX) $(LDFLAGS) -o $@ $^ $(LOADLIBES) $(LDLIBS)
./test

morat-havannah: \
havannah/main.o \
havannah/agentmcts.o \
havannah/agentmctsthread.o \
havannah/agentpns.o \
havannah/board.o \
havannah/gtpgeneral.o \
havannah/gtpagent.o \
lib/fileio.o \
lib/gtpcommon.o \
lib/outcome.o \
lib/string.o \
lib/zobrist.o \
$(ALARM)
$(CXX) $(LDFLAGS) -o $@ $^ $(LOADLIBES) $(LDLIBS)

pentagod: \
pentago/pentagod.o \
morat-pentago: \
pentago/main.o \
pentago/agentab.o \
pentago/agentmcts.o \
pentago/agentmctsthread.o \
pentago/agentpns.o \
pentago/board.o \
pentago/gtpgeneral.o \
pentago/gtpagent.o \
pentago/move.o \
pentago/moveiterator.o \
lib/fileio.o \
lib/gtpcommon.o \
lib/outcome.o \
lib/string.o \
$(ALARM)
$(CXX) $(LDFLAGS) -o $@ $^ $(LOADLIBES) $(LDLIBS)

moy: \
y/moy.o \
morat-y: \
y/main.o \
y/agentmcts.o \
y/agentmctsthread.o \
y/agentpns.o \
y/board.o \
y/gtpagent.o \
y/gtpgeneral.o \
lib/fileio.o \
lib/gtpcommon.o \
lib/outcome.o \
lib/string.o \
lib/zobrist.o \
$(ALARM)
$(CXX) $(LDFLAGS) -o $@ $^ $(LOADLIBES) $(LDLIBS)

chex: \
hex/chex.o \
morat-hex: \
hex/main.o \
hex/agentmcts.o \
hex/agentmctsthread.o \
hex/agentpns.o \
hex/board.o \
hex/gtpagent.o \
hex/gtpgeneral.o \
lib/fileio.o \
lib/gtpcommon.o \
lib/outcome.o \
lib/string.o \
lib/zobrist.o \
$(ALARM)
$(CXX) $(LDFLAGS) -o $@ $^ $(LOADLIBES) $(LDLIBS)
trex: \
rex/trex.o \

morat-rex: \
rex/main.o \
rex/agentmcts.o \
rex/agentmctsthread.o \
rex/agentpns.o \
rex/board.o \
rex/gtpagent.o \
rex/gtpgeneral.o \
lib/fileio.o \
lib/gtpcommon.o \
lib/outcome.o \
lib/string.o \
lib/zobrist.o \
$(ALARM)
$(CXX) $(LDFLAGS) -o $@ $^ $(LOADLIBES) $(LDLIBS)

clean:
rm -f */*.o castro moy pentagod chex trex .Makefile
rm -f */*.o test morat-havannah morat-hex morat-pentago morat-rex morat-y .Makefile

fresh: clean all

Expand Down
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@

Morat is a game playing framework, along with implementations of several games. It includes some general purpose libraries (alarm, time, thread, random), and some game specific libraries (compacting tree, gtp, time controls).

So far it supports 3 games:
It specializes in 2-player, perfect information, zero sum, deterministic games, especially placement games (where RAVE works).

So far it supports 5 games:
* [Havannah](https://en.wikipedia.org/wiki/Havannah)
* [Hex](https://en.wikipedia.org/wiki/Hex_%28board_game%29)
* Rex - Reverse Hex (ie try to force the opponent to connect their edges).
* [Y](https://en.wikipedia.org/wiki/Y_%28game%29)
* [Pentago](https://en.wikipedia.org/wiki/Pentago)

Potential games:
* [Gomoku](https://en.wikipedia.org/wiki/Gomoku) or more generally [M,n,k](https://en.wikipedia.org/wiki/M,n,k-game)
* [Star](https://en.wikipedia.org/wiki/Star_%28board_game%29) or [*Star](https://en.wikipedia.org/wiki/*Star)
* [Domineering or Cram](https://en.wikipedia.org/wiki/Domineering)
* [Dots and Boxes](https://en.wikipedia.org/wiki/Dots_and_Boxes)

So far it supports 3 algorithms:
* [MCTS: Monte-Carlo Tree Search](https://en.wikipedia.org/wiki/Monte-Carlo_tree_search)
* [PNS: Proof Number Search](https://en.wikipedia.org/wiki/Proof-number_search)
* [AB: Alpha-Beta](https://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruning)

Potential algorithms:
* [Probability Search](http://www.lamsade.dauphine.fr/~cazenave/papers/probabilitySearch.pdf)
* Conspiracy Number Search

The goal is to make the algorithms game independent, and make it easier to implement new games with strong players. There is quite a bit of work left to make this a reality, so the current work is just to make the game code more similar and then move the code into common libraries.

The primary interface is [GTP (Go Text Protocol)](https://en.wikipedia.org/wiki/Go_Text_Protocol), which can be used from:
Expand All @@ -30,9 +44,13 @@ The primary interface is [GTP (Go Text Protocol)](https://en.wikipedia.org/wiki/
* Check out the code from github
* Run ```make``` to compile the code
* Run:
* ```./castro``` for Havannah
* ```./moy``` for Y
* ```./pentagod``` for pentago
* ```./morat-havannah``` for Havannah
* ```./morat-hex``` for Hex
* ```./morat-rex``` for Reverse Hex
* ```./morat-y``` for Y
* ```./morat-pentago``` for pentago

Run ```make test``` to run the test suite. Current test coverage is pretty bad.

If you make any changes to the code and want to update the dependencies, just ```make clean```, or ```rm .Makefile```.

Expand Down
54 changes: 34 additions & 20 deletions havannah/agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@

//Interface for the various agents: players and solvers

#include "../lib/outcome.h"
#include "../lib/sgf.h"
#include "../lib/types.h"

#include "board.h"


namespace Morat {
namespace Havannah {

class Agent {
protected:
typedef std::vector<Move> vecmove;
public:
Agent() { }
virtual ~Agent() { }
Expand All @@ -19,51 +27,57 @@ class Agent {
virtual void set_memlimit(uint64_t lim) = 0; // in bytes
virtual void clear_mem() = 0;

virtual vector<Move> get_pv() const = 0;
string move_stats() const { return move_stats(vector<Move>()); }
virtual string move_stats(const vector<Move> moves) const = 0;
virtual vecmove get_pv() const = 0;
std::string move_stats() const { return move_stats(vecmove()); }
virtual std::string move_stats(const vecmove moves) const = 0;
virtual double gamelen() const = 0;

virtual void timedout(){ timeout = true; }

virtual void gen_sgf(SGFPrinter<Move> & sgf, int limit) const = 0;
virtual void load_sgf(SGFParser<Move> & sgf) = 0;

protected:
volatile bool timeout;
Board rootboard;

static int solve1ply(const Board & board, unsigned int & nodes) {
int outcome = -3;
int turn = board.toplay();
static Outcome solve1ply(const Board & board, unsigned int & nodes) {
Outcome outcome = Outcome::UNKNOWN;
Side turn = board.toplay();
for(Board::MoveIterator move = board.moveit(true); !move.done(); ++move){
++nodes;
int won = board.test_win(*move, turn);
Outcome won = board.test_outcome(*move, turn);

if(won == turn)
if(won == +turn)
return won;
if(won == 0)
outcome = 0;
if(won == Outcome::DRAW)
outcome = Outcome::DRAW;
}
return outcome;
}

static int solve2ply(const Board & board, unsigned int & nodes) {
static Outcome solve2ply(const Board & board, unsigned int & nodes) {
int losses = 0;
int outcome = -3;
int turn = board.toplay(), opponent = 3 - turn;
Outcome outcome = Outcome::UNKNOWN;
Side turn = board.toplay();
Side op = ~turn;
for(Board::MoveIterator move = board.moveit(true); !move.done(); ++move){
++nodes;
int won = board.test_win(*move, turn);
Outcome won = board.test_outcome(*move, turn);

if(won == turn)
if(won == +turn)
return won;
if(won == 0)
outcome = 0;
if(won == Outcome::DRAW)
outcome = Outcome::DRAW;

if(board.test_win(*move, opponent) > 0)
if(board.test_outcome(*move, op) == +op)
losses++;
}
if(losses >= 2)
return opponent;
return (Outcome)op;
return outcome;
}

};

}; // namespace Havannah
}; // namespace Morat
Loading

0 comments on commit 1632e35

Please sign in to comment.