00001
00002
00003 #include "osl/c/facade.h"
00004 #include "osl/checkmate/dualCheckmateSearcher.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
00013 extern "C"
00014 int checkmate_attack(const char *state_str, int limit, char *move)
00015 {
00016 osl::DualCheckmateSearcher<> checkmate;
00017 osl::Move checkmate_move;
00018 osl::NumEffectState state(osl::CsaString(state_str).getInitialState());
00019 osl::HashKey key = osl::HashKey::calcHash(state);
00020 osl::PathEncoding pe(state.getTurn());
00021 const bool win = checkmate.isWinningState(limit, state, key, pe,
00022 checkmate_move);
00023 if (win) {
00024 const std::string checkmate_move_str =
00025 osl::record::csa::show(checkmate_move);
00026 sprintf(move, "%s", checkmate_move_str.c_str());
00027 }
00028 return win;
00029 }
00030
00031 extern "C"
00032 int checkmate_escape(const char *state_str, int limit)
00033 {
00034 osl::DualCheckmateSearcher<> checkmate;
00035 osl::Move checkmate_move;
00036 osl::NumEffectState state(osl::CsaString(state_str).getInitialState());
00037 osl::HashKey key = osl::HashKey::calcHash(state);
00038 osl::PathEncoding pe(state.getTurn());
00039 const bool escape = checkmate.isLosingState(limit, state, key, pe);
00040 return escape;
00041 }
00042
00043 extern "C"
00044 int search(const char *state_str, int seconds, int verbose, char *move)
00045 {
00046 osl::game_playing::AlphaBeta2Player player;
00047 player.setNextIterationCoefficient(1.7);
00048 player.setTableLimit(3000000, 0);
00049 player.setVerbose(verbose);
00050 player.setDepthLimit(2000, 400, 200);
00051
00052 osl::game_playing::GameState state(osl::CsaString(state_str).getInitialState());
00053 osl::Move best_move = player.searchWithSecondsForThisMove(state, seconds).move;
00054
00055 const std::string best_move_str = osl::record::csa::show(best_move);
00056 sprintf(move, "%s", best_move_str.c_str());
00057
00058 const osl::SimpleHashTable *table = player.table();
00059 const osl::HashKey& key = state.state().getHash();
00060
00061 const osl::SimpleHashRecord *record = table->find(key);
00062 int value = record ? record->lowerBound() : 0;
00063 return value;
00064 }
00065
00066
00067
00068
00069
00070