Skip to content

Commit

Permalink
GTP command uct_policy_moves_simple; add playout policy tests
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.code.sf.net/p/fuego/code/trunk@1967 2e953b5c-c64d-0410-be54-f773e93e544c
  • Loading branch information
mmueller65 committed Dec 16, 2014
1 parent 19af315 commit 219c26e
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 9 deletions.
27 changes: 25 additions & 2 deletions gouct/GoUctCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ void GoUctCommands::AddGoGuiAnalyzeCommands(GtpCommand& cmd)
"plist/Uct Patterns/uct_patterns\n"
"pstring/Uct Policy Corrected Moves/uct_policy_corrected_moves\n"
"pstring/Uct Policy Moves/uct_policy_moves\n"
"pstring/Uct Policy Moves Simple List/uct_policy_moves_simple\n"
"gfx/Uct Prior Knowledge/uct_prior_knowledge\n"
"sboard/Uct Rave Values/uct_rave_values\n"
"plist/Uct Root Filter/uct_root_filter\n"
Expand Down Expand Up @@ -1093,7 +1094,7 @@ void GoUctCommands::CmdPolicyCorrectedMoves(GtpCommand& cmd)
See GoUctPlayoutPolicy::GetEquivalentBestMoves() <br>
Arguments: none <br>
Returns: Move type string followed by move list on a single line. */
void GoUctCommands::CmdPolicyMoves(GtpCommand& cmd)
void GoUctCommands::WritePolicyMoves(GtpCommand& cmd, bool writeGammas)
{
cmd.CheckArgNone();
GoUctPlayoutPolicy<GoBoard> policy(m_bd, Player().m_playoutPolicyParam);
Expand All @@ -1111,10 +1112,30 @@ void GoUctCommands::CmdPolicyMoves(GtpCommand& cmd)
if (policy.MoveType() == GOUCT_GAMMA_PATTERN)
{
cmd << ' ';
policy.GammaGenerator().WriteMovesAndGammas(cmd);
policy.GammaGenerator().WriteMovesAndGammas(cmd, writeGammas);
}
}

/** Return equivalent best moves in playout policy.
See GoUctPlayoutPolicy::GetEquivalentBestMoves() <br>
Arguments: none <br>
Returns: Move type string followed by move list on a single line.
For non-uniform generators, also write selection weights (gammas)
*/
void GoUctCommands::CmdPolicyMoves(GtpCommand& cmd)
{
WritePolicyMoves(cmd, true); // do write move weights (gammas)
}

/** Return equivalent best moves in playout policy.
See GoUctPlayoutPolicy::GetEquivalentBestMoves() <br>
Arguments: none <br>
Returns: Move type string followed by move list on a single line. */
void GoUctCommands::CmdPolicyMovesSimple(GtpCommand& cmd)
{
WritePolicyMoves(cmd, false); // don't write move weights (gammas)
}

/** Show total prior knowledge */
void GoUctCommands::CmdPriorKnowledge(GtpCommand& cmd)
{
Expand Down Expand Up @@ -1652,6 +1673,8 @@ void GoUctCommands::Register(GtpEngine& e)
Register(e, "uct_policy_corrected_moves",
&GoUctCommands::CmdPolicyCorrectedMoves);
Register(e, "uct_policy_moves", &GoUctCommands::CmdPolicyMoves);
Register(e, "uct_policy_moves_simple",
&GoUctCommands::CmdPolicyMovesSimple);
Register(e, "uct_prior_knowledge", &GoUctCommands::CmdPriorKnowledge);
Register(e, "uct_rave_values", &GoUctCommands::CmdRaveValues);
Register(e, "uct_root_filter", &GoUctCommands::CmdRootFilter);
Expand Down
4 changes: 4 additions & 0 deletions gouct/GoUctCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class GoUctCommands
- @link CmdPolicyCorrectedMoves() @c uct_policy_corrected_moves
@endlink
- @link CmdPolicyMoves() @c uct_policy_moves @endlink
- @link CmdPolicyMovesSimple() @c uct_policy_moves_simple @endlink
- @link CmdPriorKnowledge() @c uct_prior_knowledge @endlink
- @link CmdRaveValues() @c uct_rave_values @endlink
- @link CmdRootFilter() @c uct_root_filter @endlink
Expand Down Expand Up @@ -118,6 +119,7 @@ class GoUctCommands
void CmdPatterns(GtpCommand& cmd);
void CmdPolicyCorrectedMoves(GtpCommand& cmd);
void CmdPolicyMoves(GtpCommand& cmd);
void CmdPolicyMovesSimple(GtpCommand& cmd);
void CmdPriorKnowledge(GtpCommand& cmd);
void CmdRaveValues(GtpCommand& cmd);
void CmdRootFilter(GtpCommand& cmd);
Expand Down Expand Up @@ -187,6 +189,8 @@ class GoUctCommands

GoUctGlobalSearchState<GoUctPlayoutPolicy<GoUctBoard> >&
ThreadState(unsigned int threadId);

void WritePolicyMoves(GtpCommand& cmd, bool writeGammas);
};

//----------------------------------------------------------------------------
Expand Down
11 changes: 7 additions & 4 deletions gouct/GoUctGammaMoveGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GoUctGammaMoveGenerator

int NuMoves() const;

void WriteMovesAndGammas(std::ostream& stream) const;
void WriteMovesAndGammas(std::ostream& stream, bool writeGammas) const;

private:
/** Generate pattern moves with gamma values */
Expand Down Expand Up @@ -222,12 +222,15 @@ std::ostream& operator<<(std::ostream& stream,

template<class BOARD>
void GoUctGammaMoveGenerator<BOARD>::
WriteMovesAndGammas(std::ostream& stream) const
WriteMovesAndGammas(std::ostream& stream, bool writeGammas) const
{
for (int i = 0; i < NuMoves(); ++i)
{
stream << SgWritePoint(GetGammaMoveAt(i)) << ":"
<< GetGammaValueForMoveAt(i) << " ";
stream << SgWritePoint(GetGammaMoveAt(i));
if (writeGammas)
stream << ":"
<< GetGammaValueForMoveAt(i);
stream << ' ';
}
stream << std::endl;
}
Expand Down
4 changes: 4 additions & 0 deletions regression/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,11 @@ sgf/playout/playout_atari_defense_1.sgf \
sgf/playout/playout_atari_defense_2.sgf \
sgf/playout/playout_atari_defense_3.sgf \
sgf/playout/playout_capture_1.sgf \
sgf/playout/playout_capture_no_selfatari.1.sgf \
sgf/playout/playout_capture_no_selfatari.2.sgf \
sgf/playout/playout_nakade.1.sgf \
sgf/playout/playout_nakade.2.sgf \
sgf/playout/playout_nakade.3.sgf \
sgf/playout/playout_nakade_approach.sgf \
sgf/playout/playout_two_liberties_semeai.1.sgf \
sgf/playout/playout_two_liberties_semeai.2.sgf \
Expand Down
20 changes: 20 additions & 0 deletions regression/playout_atari_capture.tst
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,23 @@ loadsgf sgf/playout/playout_two_liberties_semeai.3.sgf 4
201 uct_policy_moves
#? [AtariCapture J7]*
# current policy captures F4...

#-----------------------------------------------------------------------------
# Good capture vs. Selfatari capture

loadsgf sgf/playout/playout_capture_no_selfatari.1.sgf
210 reg_genmove w
#? [H2]

211 uct_policy_moves
#? [AtariCapture H2]*
# current policy captures J8, selfatari

loadsgf sgf/playout/playout_capture_no_selfatari.2.sgf
220 reg_genmove w
#? [H2]*

221 uct_policy_moves
#? [AtariCapture H2]*
# current policy captures J8, selfatari

14 changes: 11 additions & 3 deletions regression/playout_nakade.tst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ loadsgf sgf/playout/playout_nakade.1.sgf 7
#? [J8]
# must kill on vital point.

31 uct_policy_moves
#? [Pattern J8]
# Should be different move reason in future ???
31 uct_policy_moves_simple
#? [GammaPattern J8]
# Should be different move reason in future ???

loadsgf sgf/playout/playout_nakade.2.sgf
40 uct_policy_moves
#? [GammaPattern E1:1 F1:550.309]
# F1 is much more likely, but E1 would be fatal...

41 uct_policy_moves_simple
#? [GammaPattern F1]*
5 changes: 5 additions & 0 deletions regression/sgf/playout/playout_capture_no_selfatari.1.sgf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(;FF[4]CA[UTF-8]AP[GoGui:1.4.9]SZ[9]
KM[0.5]DT[2014-12-16]
AB[ae][bf][be][ce][cd][cc][df][de][ee][ed][ec][eb][ff][fd][fb][fa][gi][gh][gf][gd][hi][hg][hf][hb][ii][ih]
AW[ag][af][bg][ch][cg][cf][dg][eg][ef][fi][fh][fg][fe][fc][gg][ge][gc][gb][ga][he][hd][hc][ha][ig][if][ie][id][ic][ia]
PL[W])
5 changes: 5 additions & 0 deletions regression/sgf/playout/playout_capture_no_selfatari.2.sgf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(;FF[4]CA[UTF-8]AP[GoGui:1.4.9]SZ[9]
KM[0.5]DT[2014-12-16]
AB[ae][bf][be][ce][cd][cc][df][de][ee][ed][ec][eb][ff][fd][fb][fa][gi][gh][gf][gd][hi][hg][hf][ii][ih]
AW[ag][af][bg][ch][cg][cf][dg][eg][ef][fi][fh][fg][fe][fc][gg][ge][gc][gb][ga][he][hd][hc][ha][ig][if][ie][id][ic][ia]
PL[B];B[hb])
3 changes: 3 additions & 0 deletions regression/sgf/playout/playout_nakade.2.sgf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(;FF[4]CA[UTF-8]AP[GoGui:1.4.9]SZ[9]
KM[7.5]DT[2014-12-16]
AB[di][dh][eh][eg][ef][ff][gf][gg][gh][gi]PL[W];W[fh])
3 changes: 3 additions & 0 deletions regression/sgf/playout/playout_nakade.3.sgf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(;FF[4]CA[UTF-8]AP[GoGui:1.4.9]SZ[9]
KM[7.5]DT[2014-12-16]
AB[di][dh][eh][eg][ef][ff][gf][gg][gh][gi]PL[W];W[fi])

0 comments on commit 219c26e

Please sign in to comment.