00001
00002
00003 #include "osl/c/facade.h"
00004 #include "osl/checkmate/dualDfpn.h"
00005 #include "osl/game_playing/alphaBetaPlayer.h"
00006 #include "osl/game_playing/gameState.h"
00007 #include "osl/search/simpleHashTable.h"
00008 #include "osl/search/simpleHashRecord.h"
00009 #include "osl/record/csaString.h"
00010 #include "osl/record/csa.h"
00011 #include <string>
00012 #include <cstdio>
00013
00014 extern "C"
00015 int checkmate_attack(const char *state_str, int& limit, char *move)
00016 {
00017 osl::DualDfpn checkmate;
00018 osl::Move checkmate_move;
00019 osl::NumEffectState state(osl::CsaString(state_str).getInitialState());
00020 osl::HashKey key(state);
00021 osl::PathEncoding pe(state.getTurn());
00022 const bool win = checkmate.isWinningState(limit, state, key, pe,
00023 checkmate_move);
00024 limit = checkmate.totalNodeCount();
00025 if (win) {
00026 const std::string checkmate_move_str =
00027 osl::record::csa::show(checkmate_move);
00028 sprintf(move, "%s", checkmate_move_str.c_str());
00029 }
00030 return win;
00031 }
00032
00033 extern "C"
00034 int checkmate_escape(const char *state_str, int limit)
00035 {
00036 osl::DualDfpn checkmate;
00037 osl::Move checkmate_move;
00038 osl::NumEffectState state(osl::CsaString(state_str).getInitialState());
00039 osl::HashKey key(state);
00040 osl::PathEncoding pe(state.getTurn());
00041 const bool escape = checkmate.isLosingState(limit, state, key, pe);
00042 return escape;
00043 }
00044
00045 extern "C"
00046 int search(const char *state_str, int seconds, int verbose, char *move)
00047 {
00048 osl::game_playing::AlphaBeta2OpenMidEndingEvalPlayer player;
00049 player.setNextIterationCoefficient(1.7);
00050 player.setVerbose(verbose);
00051 if (osl::OslConfig::isMemoryLimitEffective())
00052 {
00053 player.setTableLimit(std::numeric_limits<size_t>::max(), 200);
00054 player.setNodeLimit(std::numeric_limits<size_t>::max());
00055 }
00056 else
00057 {
00058 player.setTableLimit(3000000, 200);
00059 }
00060 player.setDepthLimit(2000, 400, 200);
00061
00062 osl::game_playing::GameState state(osl::CsaString(state_str).getInitialState());
00063 osl::Move best_move = player.searchWithSecondsForThisMove(state, osl::search::TimeAssigned(osl::MilliSeconds::Interval(seconds*1000))).move;
00064
00065 const std::string best_move_str = osl::record::csa::show(best_move);
00066 sprintf(move, "%s", best_move_str.c_str());
00067
00068 const osl::SimpleHashTable *table = player.table();
00069 const osl::HashKey key(state.state());
00070
00071 const osl::SimpleHashRecord *record = table->find(key);
00072 int value = record ? record->lowerBound() : 0;
00073 return value;
00074 }
00075
00076
00077
00078
00079
00080