Go to the documentation of this file.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 void osl_init()
00016 {
00017 osl::OslConfig::setUp();
00018 }
00019
00020 extern "C"
00021 int checkmate_attack(const char *state_str, int& limit, char *move)
00022 {
00023 osl::DualDfpn checkmate;
00024 osl::Move checkmate_move;
00025 osl::NumEffectState state(osl::CsaString(state_str).getInitialState());
00026 osl::HashKey key(state);
00027 osl::PathEncoding pe(state.turn());
00028 const bool win = checkmate.isWinningState(limit, state, key, pe,
00029 checkmate_move);
00030 limit = checkmate.totalNodeCount();
00031 if (win) {
00032 const std::string checkmate_move_str =
00033 osl::record::csa::show(checkmate_move);
00034 sprintf(move, "%s", checkmate_move_str.c_str());
00035 }
00036 return win;
00037 }
00038
00039 extern "C"
00040 int checkmate_escape(const char *state_str, int limit)
00041 {
00042 osl::DualDfpn checkmate;
00043 osl::Move checkmate_move;
00044 osl::NumEffectState state(osl::CsaString(state_str).getInitialState());
00045 osl::HashKey key(state);
00046 osl::PathEncoding pe(state.turn());
00047 const bool escape = checkmate.isLosingState(limit, state, key, pe);
00048 return escape;
00049 }
00050
00051 extern "C"
00052 int search(const char *state_str, int seconds, int verbose, char *move)
00053 {
00054 osl::game_playing::AlphaBeta2OpenMidEndingEvalPlayer player;
00055 player.setNextIterationCoefficient(1.7);
00056 player.setVerbose(verbose);
00057 if (osl::OslConfig::isMemoryLimitEffective())
00058 {
00059 player.setTableLimit(std::numeric_limits<size_t>::max(), 200);
00060 player.setNodeLimit(std::numeric_limits<size_t>::max());
00061 }
00062 else
00063 {
00064 player.setTableLimit(3000000, 200);
00065 }
00066 player.setDepthLimit(2000, 400, 200);
00067
00068 osl::game_playing::GameState state(osl::CsaString(state_str).getInitialState());
00069 osl::Move best_move = player.searchWithSecondsForThisMove(state, osl::search::TimeAssigned(osl::MilliSeconds::Interval(seconds*1000))).move;
00070
00071 const std::string best_move_str = osl::record::csa::show(best_move);
00072 sprintf(move, "%s", best_move_str.c_str());
00073
00074 const osl::SimpleHashTable *table = player.table();
00075 const osl::HashKey key(state.state());
00076
00077 const osl::SimpleHashRecord *record = table->find(key);
00078 int value = record ? record->lowerBound() : 0;
00079 return value;
00080 }
00081
00082
00083
00084
00085
00086