├── .gitignore ├── COPYING ├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── net │ │ └── lrstudios │ │ └── android │ │ └── pachi │ │ ├── MainActivity.java │ │ ├── MyApplication.java │ │ └── PachiEngine.java │ └── res │ ├── drawable-hdpi │ └── ic_home.png │ ├── drawable-mdpi │ └── ic_home.png │ ├── drawable-xhdpi │ └── ic_home.png │ ├── raw │ └── pachi │ └── values │ └── strings.xml ├── build.gradle ├── debug.keystore ├── elygo-lib ├── .gitignore ├── COPYING ├── README ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── lrstudios │ │ ├── games │ │ └── ego │ │ │ └── lib │ │ │ ├── BoardAnimation.java │ │ │ ├── BoardLabelMark.java │ │ │ ├── BoardMark.java │ │ │ ├── BoardView.java │ │ │ ├── Coords.java │ │ │ ├── DetailedSeekBar.java │ │ │ ├── ExternalGtpEngine.java │ │ │ ├── GameInfo.java │ │ │ ├── GameNode.java │ │ │ ├── GoBoard.java │ │ │ ├── GoGame.java │ │ │ ├── GoGameResult.java │ │ │ ├── GtpEngine.java │ │ │ ├── GtpThread.java │ │ │ ├── IntentGameInfo.java │ │ │ ├── LibConfig.java │ │ │ ├── LightCoords.java │ │ │ ├── LrfParser.java │ │ │ ├── PrisonersView.java │ │ │ ├── ScoreView.java │ │ │ ├── SgfParser.java │ │ │ ├── TypefaceCache.java │ │ │ ├── UpdatePrefsTask.java │ │ │ ├── Utils.java │ │ │ ├── themes │ │ │ ├── BlackWhiteTheme.java │ │ │ ├── DarkBoardTheme.java │ │ │ ├── StandardTheme.java │ │ │ └── Theme.java │ │ │ ├── ui │ │ │ ├── BaseBoardActivity.java │ │ │ ├── GtpBoardActivity.java │ │ │ ├── NewGameActivity.java │ │ │ └── Preferences.java │ │ │ └── util │ │ │ ├── GoUtils.java │ │ │ ├── HoloDialog.java │ │ │ └── SoundHelper.java │ │ └── util │ │ ├── EventListenerList.java │ │ ├── Rect.java │ │ ├── android │ │ ├── AndroidUtils.java │ │ └── ui │ │ │ └── BetterFragmentActivity.java │ │ └── io │ │ ├── BitContainer.java │ │ ├── BitReader.java │ │ └── BitWriter.java │ └── res │ ├── anim │ ├── fragment_fade_in.xml │ └── fragment_fade_out.xml │ ├── drawable-mdpi │ └── list_extra_button_left_border.9.png │ ├── drawable-nodpi │ ├── actionbar_top_bg.9.png │ ├── login_frame.9.png │ ├── wood2.png │ └── wood6.png │ ├── drawable-xhdpi │ ├── __btn_default_disabled_focused_holo_light.9.png │ ├── __btn_default_disabled_holo_light.9.png │ ├── __btn_default_focused_holo_light.9.png │ ├── __btn_default_normal_holo_light.9.png │ ├── __btn_default_pressed_holo_light.9.png │ ├── __btn_green_normal_holo_light.9.png │ ├── __btn_red_normal_holo_light.9.png │ ├── dialog_full_holo_light.9.png │ ├── grey_background_pattern_tile.png │ ├── grey_border_inset_lr.9.png │ ├── ic_action_help.png │ ├── ic_action_navigation_next_disabled.png │ ├── ic_action_navigation_next_enabled.png │ ├── ic_action_navigation_previous_disabled.png │ ├── ic_action_navigation_previous_enabled.png │ ├── ic_action_restart_disabled.png │ ├── ic_action_restart_enabled.png │ ├── ic_action_save_disabled.png │ ├── ic_action_save_enabled.png │ ├── ic_action_settings.png │ ├── ic_action_split_disabled.png │ ├── ic_action_split_enabled.png │ ├── ic_action_undo_disabled.png │ ├── ic_action_undo_enabled.png │ ├── ic_green_check_mark.png │ ├── ic_red_cross.png │ ├── item_activated.9.png │ ├── item_checked.9.png │ ├── item_focused.9.png │ ├── item_pressed.9.png │ └── list_extra_button_left_border.9.png │ ├── drawable │ ├── __btn_default_holo_light.xml │ ├── __btn_green_holo_light.xml │ ├── __btn_red_holo_light.xml │ ├── actionbar_shadow.9.png │ ├── activatable_grey_item_background.xml │ ├── activatable_item_background.xml │ ├── bottom_bar_bg.xml │ ├── dialog_title_bg.xml │ ├── grey_background_pattern.xml │ ├── ic_action_navigation_next.xml │ ├── ic_action_navigation_previous.xml │ ├── ic_action_restart.xml │ ├── ic_action_save.xml │ ├── ic_action_split.xml │ ├── ic_action_undo.xml │ ├── list_extra_button_bg.xml │ ├── main_top_separator.xml │ └── main_top_separator_horizontal.xml │ ├── layout-land │ └── score_panel.xml │ ├── layout │ ├── activity_with_fragment_container.xml │ ├── alert_dialog_holo.xml │ ├── board_activity.xml │ ├── detailed_seek_bar.xml │ ├── dialog_save_file.xml │ ├── newgame_activity.xml │ ├── score_panel.xml │ └── toolbar_with_progress.xml │ ├── menu │ └── actionbar_gtp_board.xml │ ├── raw │ ├── pass.mp3 │ └── stone.wav │ ├── values-de │ ├── arrays.xml │ └── strings.xml │ ├── values-es │ └── strings.xml │ ├── values-fr │ ├── arrays.xml │ └── strings.xml │ ├── values-ja │ ├── arrays.xml │ └── strings.xml │ ├── values-ko │ └── strings.xml │ ├── values-pl │ └── strings.xml │ ├── values-ru │ └── strings.xml │ ├── values │ ├── arrays.xml │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml │ └── xml │ └── preferences.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jni ├── Android.mk ├── Application.mk └── pachi │ ├── .gitignore │ ├── Android.mk │ ├── COPYING │ ├── CREDITS │ ├── HACKING │ ├── Makefile │ ├── README │ ├── TODO │ ├── android │ ├── util.c │ └── util.h │ ├── board.c │ ├── board.h │ ├── book.dat.bad │ ├── book.dat.extra │ ├── chat.c │ ├── chat.h │ ├── debug.h │ ├── distributed │ ├── Makefile │ ├── distributed.c │ ├── distributed.h │ ├── merge.c │ ├── merge.h │ ├── protocol.c │ └── protocol.h │ ├── engine.h │ ├── fbook.c │ ├── fbook.h │ ├── fixp.h │ ├── gtp.c │ ├── gtp.h │ ├── joseki │ ├── Makefile │ ├── README │ ├── base.c │ ├── base.h │ ├── joseki.c │ ├── joseki.h │ └── sgfvar2gtp.pl │ ├── joseki19.pdict │ ├── media │ ├── pachi-small.png │ └── pachi.jpg │ ├── montecarlo │ ├── Makefile │ ├── internal.h │ ├── montecarlo.c │ └── montecarlo.h │ ├── move.c │ ├── move.h │ ├── mq.h │ ├── network.c │ ├── network.h │ ├── ownermap.c │ ├── ownermap.h │ ├── pachi.c │ ├── pattern.c │ ├── pattern.h │ ├── pattern3.c │ ├── pattern3.h │ ├── patternplay │ ├── Makefile │ ├── patternplay.c │ └── patternplay.h │ ├── patternprob.c │ ├── patternprob.h │ ├── patternscan │ ├── Makefile │ ├── patternscan.c │ └── patternscan.h │ ├── patternsp.c │ ├── patternsp.h │ ├── playout.c │ ├── playout.h │ ├── playout │ ├── Makefile │ ├── light.c │ ├── light.h │ ├── moggy.c │ └── moggy.h │ ├── probdist.c │ ├── probdist.h │ ├── random.c │ ├── random.h │ ├── random │ ├── Makefile │ ├── random.c │ └── random.h │ ├── replay │ ├── Makefile │ ├── replay.c │ └── replay.h │ ├── stats.h │ ├── stone.c │ ├── stone.h │ ├── t-play │ ├── TESTS │ ├── autotest │ │ ├── README │ │ ├── TODO │ │ ├── autotest-client │ │ ├── autotest-clients │ │ ├── autotest-gather │ │ ├── autotest-lib │ │ ├── autotest-prune │ │ ├── autotest-show │ │ ├── autotest-worker │ │ └── rc │ ├── resum │ └── test_in_context.sh │ ├── t-regress │ ├── README │ ├── TODO │ ├── by-falseeye │ │ ├── 2011-06-05-Zen19-pachi2.sgf │ │ ├── 2011-06-05-tazaki-pachi30s.sgf │ │ ├── 2011-06-09-botkiller2-pachi30s.sgf │ │ ├── 2011-06-10-pachi30s-samba-2.sgf │ │ ├── 2011-06-18-dorabon-pachi2-4.sgf │ │ ├── 2011-07-28-pachi2-Novicer.sgf │ │ └── 2011-08-12-xiaosugi-pachi2.sgf │ ├── by-ko │ │ └── 2011-06-09-jinen-pachi30s-2.sgf │ ├── by-ladder │ │ ├── 2011-01-11-llopl-pachi2.sgf │ │ ├── 2011-06-06-tyzef-pachi30s.sgf │ │ ├── 2011-06-13-pachi30s-Jep.sgf │ │ ├── 2011-07-28-pachi2-pkunzip-2.sgf │ │ ├── 2011-08-08-Dallas-pachi2-2.sgf │ │ ├── 2011-08-09-pachi2-BlueSpark.sgf │ │ ├── 2011-08-09-somrak-pachi2-2.sgf │ │ ├── 2011-08-24-StoneGrid-pachi2.sgf │ │ ├── 2011-09-04-pachi2-stv.sgf │ │ └── 2012-03-16-IMC-pachi2.sgf │ ├── by-semeai │ │ ├── 2011-01-15-pachi2-rollingon.sgf │ │ ├── 2011-06-05-Zen19-pachi2.sgf │ │ ├── 2011-06-05-tazaki-pachi30s.sgf │ │ ├── 2011-06-18-dorabon-pachi2-4.sgf │ │ └── 2012-03-15-pachi2-Leech.sgf │ ├── games │ │ ├── 2010-12-05-pachi-CzechBot.sgf │ │ ├── 2011-01-11-llopl-pachi2.sgf │ │ ├── 2011-01-15-pachi2-rollingon.sgf │ │ ├── 2011-06-05-Zen19-pachi2.sgf │ │ ├── 2011-06-05-tazaki-pachi30s.sgf │ │ ├── 2011-06-06-tyzef-pachi30s.sgf │ │ ├── 2011-06-07-fidibus-pachi30s.sgf │ │ ├── 2011-06-09-botkiller2-pachi30s.sgf │ │ ├── 2011-06-09-jinen-pachi30s-2.sgf │ │ ├── 2011-06-10-pachi30s-samba-2.sgf │ │ ├── 2011-06-13-pachi30s-Jep.sgf │ │ ├── 2011-06-18-dorabon-pachi2-4.sgf │ │ ├── 2011-07-28-pachi2-Novicer.sgf │ │ ├── 2011-07-28-pachi2-pkunzip-2.sgf │ │ ├── 2011-08-08-Dallas-pachi2-2.sgf │ │ ├── 2011-08-09-pachi2-BlueSpark.sgf │ │ ├── 2011-08-09-somrak-pachi2-2.sgf │ │ ├── 2011-08-12-xiaosugi-pachi2.sgf │ │ ├── 2011-08-24-StoneGrid-pachi2.sgf │ │ ├── 2011-09-04-pachi2-stv.sgf │ │ ├── 2012-01-17-pachi2-Soromon-3.sgf │ │ ├── 2012-03-15-pachi2-Leech.sgf │ │ ├── 2012-03-16-IMC-pachi2.sgf │ │ └── 2012-03-21-pachi2-Hujisawa-3.sgf │ └── test-game.sh │ ├── t-unit │ ├── Makefile │ ├── README │ ├── sar.t │ ├── test.c │ └── test.h │ ├── tactics │ ├── 1lib.c │ ├── 1lib.h │ ├── 2lib.c │ ├── 2lib.h │ ├── Makefile │ ├── ladder.c │ ├── ladder.h │ ├── nakade.c │ ├── nakade.h │ ├── nlib.c │ ├── nlib.h │ ├── selfatari.c │ ├── selfatari.h │ ├── util.c │ └── util.h │ ├── timeinfo.c │ ├── timeinfo.h │ ├── tools │ ├── autobook │ │ ├── README │ │ ├── autobook.sh │ │ ├── autobook2fbook.sh │ │ ├── eval.sh │ │ ├── expand.sh │ │ └── walk.sh │ ├── complete-tromptaylor.gtp │ ├── complete.gtp │ ├── genmove.gtp │ ├── genmove19.gtp │ ├── gentbook.sh │ ├── kgslog2gtp.pl │ ├── pattern3_show.pl │ ├── pattern_bayes_gen.sh │ ├── pattern_bayes_merge.sh │ ├── pattern_byplayer.sh │ ├── pattern_getdrops.pl │ ├── pattern_spatial_gen.sh │ ├── pattern_spatial_show.pl │ ├── sgf-analyse.pl │ ├── sgf-ratemove.sh │ ├── sgf2gtp.pl │ ├── sgf2gtp.py │ ├── sgflib │ │ ├── .gitignore │ │ ├── __init__.py │ │ ├── sgflib.py │ │ └── typelib.py │ ├── spirit.gtp │ └── twogtp.py │ ├── uct │ ├── Makefile │ ├── dynkomi.c │ ├── dynkomi.h │ ├── internal.h │ ├── plugin.h │ ├── plugin │ │ ├── example.c │ │ └── wolf.c │ ├── plugins.c │ ├── plugins.h │ ├── policy │ │ ├── Makefile │ │ ├── generic.c │ │ ├── generic.h │ │ ├── ucb1.c │ │ └── ucb1amaf.c │ ├── prior.c │ ├── prior.h │ ├── search.c │ ├── search.h │ ├── slave.c │ ├── slave.h │ ├── tree.c │ ├── tree.h │ ├── uct.c │ ├── uct.h │ ├── walk.c │ └── walk.h │ ├── util.h │ └── version.h ├── pachi.iml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .DS_Store 3 | /local.properties 4 | /.idea 5 | /.gradle 6 | /captures 7 | /build 8 | */build 9 | /libs 10 | /obj 11 | 12 | *.bat 13 | *.sh 14 | *.keystore 15 | *.apk 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pachi for Android 2 | 3 | This is the Android version of [Pachi][1], a Go game engine developed by Petr Baudis and Jean-Loup Gailly. 4 | 5 | If you make a change to Pachi's code, you have to rebuild the executable with the [Android NDK][2]. 6 | To do this, open the `jni` folder and enter the command `ndk-build`. If you get errors, try to use the NDK version r10e. Sometimes newer versions require to make some changes to the code. Then copy the executable from `libs/armeabi` to the `app/src/main/res/raw` folder and replace the existing one. 7 | 8 | 9 | ## Credits 10 | 11 | - [The Pachi project](http://pachi.or.cz) 12 | - [elygo-lib](http://github.com/Daimas/elygo-lib) 13 | 14 | ## License 15 | 16 | Pachi for Android is distributed under the GPLv2 license (see the COPYING file for details and full text of the license). You are welcome to tweak it as you wish and distribute it freely, but only together with the source code. 17 | 18 | [1]: http://pachi.or.cz 19 | [2]: http://developer.android.com/tools/sdk/ndk/index.html 20 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 27 5 | buildToolsVersion '27.0.3' 6 | 7 | defaultConfig { 8 | applicationId 'net.lrstudios.android.pachi' 9 | minSdkVersion 21 10 | targetSdkVersion 27 11 | versionCode 12 12 | versionName '1.19' 13 | } 14 | 15 | signingConfigs { 16 | debug { 17 | storeFile file("../debug.keystore") 18 | } 19 | 20 | release { 21 | storeFile file("../release.keystore") 22 | storePassword System.getenv("KEYSTORE_PASSWORD") 23 | keyAlias "krelease" 24 | keyPassword System.getenv("KEYSTORE_PASSWORD") 25 | } 26 | } 27 | 28 | buildTypes { 29 | debug { 30 | minifyEnabled false 31 | signingConfig signingConfigs.debug 32 | } 33 | 34 | release { 35 | minifyEnabled false 36 | signingConfig signingConfigs.release 37 | } 38 | } 39 | 40 | lintOptions { 41 | abortOnError false 42 | } 43 | } 44 | 45 | dependencies { 46 | compile 'com.android.support:appcompat-v7:27.1.1' 47 | 48 | compile project(':elygo-lib') 49 | compile fileTree(dir: 'libs', include: ['*.jar']) 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 15 | 16 | 21 | 22 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 37 | 38 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/java/net/lrstudios/android/pachi/MainActivity.java: -------------------------------------------------------------------------------- 1 | package net.lrstudios.android.pachi; 2 | 3 | import lrstudios.games.ego.lib.ui.NewGameActivity; 4 | 5 | 6 | public class MainActivity extends NewGameActivity { 7 | @Override 8 | protected Class getBotClass() { 9 | return PachiEngine.class; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/net/lrstudios/android/pachi/MyApplication.java: -------------------------------------------------------------------------------- 1 | package net.lrstudios.android.pachi; 2 | 3 | import android.app.Application; 4 | 5 | public class MyApplication extends Application { 6 | @Override 7 | public void onCreate() { 8 | super.onCreate(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/app/src/main/res/drawable-hdpi/ic_home.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/app/src/main/res/drawable-mdpi/ic_home.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/app/src/main/res/drawable-xhdpi/ic_home.png -------------------------------------------------------------------------------- /app/src/main/res/raw/pachi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/app/src/main/res/raw/pachi -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Pachi 3 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | google() 5 | } 6 | 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:3.0.1' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | jcenter() 15 | google() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/debug.keystore -------------------------------------------------------------------------------- /elygo-lib/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | .idea 4 | build -------------------------------------------------------------------------------- /elygo-lib/README: -------------------------------------------------------------------------------- 1 | 2 | *** ElyGo-lib *** 3 | 4 | ElyGo-lib is the core library used by the Android application "ElyGo". 5 | It provides several features related to the game of Go (Igo, Weiqi, Baduk). 6 | 7 | 8 | *** USAGE *** 9 | 10 | It is an Android library project and cannot be run directly as it is. 11 | Check the Android documentation for more informations about library projects. 12 | 13 | You can also download the "ElyGo-bots" source code for an example on how to 14 | use this library in an application. 15 | 16 | Link : https://github.com/Daimas/elygo-bots 17 | 18 | 19 | *** Copyrights and License *** 20 | 21 | All files are under the GNU General Public License, which may be found in 22 | the file COPYING. 23 | 24 | Author : 25 | 26 | Emmanuel Mathis 27 | -------------------------------------------------------------------------------- /elygo-lib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 27 5 | buildToolsVersion '27.0.3' 6 | 7 | defaultConfig { 8 | minSdkVersion 15 9 | targetSdkVersion 27 10 | } 11 | } 12 | 13 | dependencies { 14 | compile 'com.android.support:support-v4:27.1.1' 15 | compile 'com.android.support:appcompat-v7:27.1.1' 16 | 17 | compile fileTree(dir: 'libs', include: ['*.jar', '*.aar']) 18 | } -------------------------------------------------------------------------------- /elygo-lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /elygo-lib/src/main/java/lrstudios/games/ego/lib/BoardLabelMark.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Elygo-lib. 3 | * Copyright (C) 2012 Emmanuel Mathis [emmanuel *at* lr-studios.net] 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | package lrstudios.games.ego.lib; 20 | 21 | 22 | /** 23 | * Represents a board mark with a label (usually letters or digits). 24 | */ 25 | public final class BoardLabelMark extends BoardMark { 26 | protected char _label; 27 | 28 | public BoardLabelMark(int x, int y, char label) { 29 | super(x, y, MARK_LABEL); 30 | _label = label; 31 | } 32 | 33 | 34 | /** 35 | * {@inheritDoc} 36 | */ 37 | @Override 38 | public char getLabel() { 39 | return _label; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /elygo-lib/src/main/java/lrstudios/games/ego/lib/BoardMark.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Elygo-lib. 3 | * Copyright (C) 2012 Emmanuel Mathis [emmanuel *at* lr-studios.net] 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | package lrstudios.games.ego.lib; 20 | 21 | 22 | /** 23 | * Represents a mark on a Go Board (like triangles, squares, letters, ...). 24 | */ 25 | public class BoardMark { 26 | public static final byte 27 | NO_MARK = 0, 28 | MARK_TRIANGLE = 1, 29 | MARK_CIRCLE = 2, 30 | MARK_SQUARE = 3, 31 | MARK_CROSS = 4, 32 | MARK_WHITE_TERRITORY = 5, 33 | MARK_BLACK_TERRITORY = 6, 34 | MARK_WHITE_TRANSPARENT = 7, 35 | MARK_BLACK_TRANSPARENT = 8, 36 | MARK_LABEL = 9, 37 | MARK_ADD_BLACK = 50, 38 | MARK_ADD_WHITE = 51, 39 | MARK_ADD_EMPTY = 52; 40 | 41 | 42 | /** 43 | * The mark type : one of the MARK_* constants. 44 | */ 45 | public byte type; 46 | public byte x; 47 | public byte y; 48 | 49 | 50 | /** 51 | * Creates a new Board Mark. 52 | */ 53 | public BoardMark(int x, int y, byte type) { 54 | this.type = type; 55 | this.x = (byte) x; 56 | this.y = (byte) y; 57 | } 58 | 59 | public short getIntersection(int size) { 60 | return (short) (y * size + x); 61 | } 62 | 63 | 64 | /** 65 | * Returns the label associated with this mark (or '\0' if there is none). 66 | */ 67 | public char getLabel() { 68 | return 0; 69 | } 70 | 71 | 72 | @Override 73 | public String toString() { 74 | return "[BoardMark] type = " + type + " at (" + x + ", " + y + ")"; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /elygo-lib/src/main/java/lrstudios/games/ego/lib/Coords.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Elygo-lib. 3 | * Copyright (C) 2012 Emmanuel Mathis [emmanuel *at* lr-studios.net] 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | package lrstudios.games.ego.lib; 20 | 21 | 22 | /** 23 | * Represents a point defined by two coordinates. 24 | */ 25 | public final class Coords { 26 | public int x; 27 | public int y; 28 | 29 | 30 | public Coords() { 31 | } 32 | 33 | public Coords(final int x, final int y) { 34 | this.x = x; 35 | this.y = y; 36 | } 37 | 38 | public void set(final int x, final int y) { 39 | this.x = x; 40 | this.y = y; 41 | } 42 | 43 | 44 | @Override 45 | public String toString() { 46 | return String.format("(%d, %d)", x, y); 47 | } 48 | 49 | 50 | /** 51 | * Returns true if the specified object have the same coordinates that the current object. 52 | */ 53 | @Override 54 | public boolean equals(Object obj) { 55 | if (obj instanceof Coords) { 56 | Coords coords = (Coords) obj; 57 | return x == coords.x && y == coords.y; 58 | } 59 | return false; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /elygo-lib/src/main/java/lrstudios/games/ego/lib/IntentGameInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Elygo-lib. 3 | * Copyright (C) 2012 Emmanuel Mathis [emmanuel *at* lr-studios.net] 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | package lrstudios.games.ego.lib; 20 | 21 | import android.os.Parcel; 22 | import android.os.Parcelable; 23 | 24 | 25 | /** 26 | * This parcelable class is passed to a BoardActivity to start a new game 27 | * with the specified parameters. 28 | */ 29 | public final class IntentGameInfo implements Parcelable { 30 | public int boardSize; 31 | public int handicap; 32 | public byte color; 33 | public double komi; 34 | public int botLevel; 35 | public String rules = ""; 36 | 37 | 38 | public IntentGameInfo() { 39 | } 40 | 41 | public IntentGameInfo(Parcel in) { 42 | boardSize = in.readInt(); 43 | handicap = in.readInt(); 44 | color = in.readByte(); 45 | komi = in.readDouble(); 46 | botLevel = in.readInt(); 47 | rules = in.readString(); 48 | } 49 | 50 | 51 | @Override 52 | public int describeContents() { 53 | return 0; 54 | } 55 | 56 | @Override 57 | public void writeToParcel(Parcel parcel, int i) { 58 | parcel.writeInt(boardSize); 59 | parcel.writeInt(handicap); 60 | parcel.writeByte(color); 61 | parcel.writeDouble(komi); 62 | parcel.writeInt(botLevel); 63 | parcel.writeString(rules); 64 | } 65 | 66 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 67 | @Override 68 | public IntentGameInfo createFromParcel(Parcel source) { 69 | return new IntentGameInfo(source); 70 | } 71 | 72 | @Override 73 | public IntentGameInfo[] newArray(int size) { 74 | return new IntentGameInfo[size]; 75 | } 76 | }; 77 | } 78 | -------------------------------------------------------------------------------- /elygo-lib/src/main/java/lrstudios/games/ego/lib/LibConfig.java: -------------------------------------------------------------------------------- 1 | package lrstudios.games.ego.lib; 2 | 3 | 4 | public class LibConfig { 5 | public static final String ASSET_ROBOTO_LIGHT = "fonts/Roboto-Light.ttf"; 6 | public static final String ASSET_ROBOTO_REGULAR = "fonts/Roboto-Regular.ttf"; 7 | public static final String ASSET_ROBOTO_BOLD = "fonts/Roboto-Bold.ttf"; 8 | } 9 | -------------------------------------------------------------------------------- /elygo-lib/src/main/java/lrstudios/games/ego/lib/LightCoords.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Elygo-lib. 3 | * Copyright (C) 2012 Emmanuel Mathis [emmanuel *at* lr-studios.net] 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | package lrstudios.games.ego.lib; 20 | 21 | /** 22 | * These move coordinates are stored in 3 bytes, to reduce memory usage on Android. 23 | */ 24 | public final class LightCoords { 25 | public byte x; 26 | public byte y; 27 | public byte color; 28 | 29 | public LightCoords(int x, int y, byte color) { 30 | this.x = (byte) x; 31 | this.y = (byte) y; 32 | this.color = color; 33 | } 34 | 35 | 36 | /** 37 | * Ne compare que les coordonnées, pas la couleur. 38 | */ 39 | @Override 40 | public boolean equals(Object obj) { 41 | if (obj instanceof LightCoords) { 42 | LightCoords coords = (LightCoords) obj; 43 | return x == coords.x && y == coords.y; 44 | } 45 | return false; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /elygo-lib/src/main/java/lrstudios/games/ego/lib/TypefaceCache.java: -------------------------------------------------------------------------------- 1 | package lrstudios.games.ego.lib; 2 | 3 | import android.content.res.AssetManager; 4 | import android.graphics.Typeface; 5 | 6 | import java.util.Hashtable; 7 | 8 | 9 | public class TypefaceCache { 10 | private static final Hashtable cache = new Hashtable(); 11 | 12 | public static Typeface get(AssetManager assetMgr, String assetPath) { 13 | synchronized (cache) { 14 | if (!cache.containsKey(assetPath)) { 15 | Typeface typeface = Typeface.createFromAsset(assetMgr, assetPath); 16 | cache.put(assetPath, typeface); 17 | } 18 | return cache.get(assetPath); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /elygo-lib/src/main/java/lrstudios/games/ego/lib/UpdatePrefsTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Elygo-lib. 3 | * Copyright (C) 2012 Emmanuel Mathis [emmanuel *at* lr-studios.net] 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | package lrstudios.games.ego.lib; 20 | 21 | import android.content.SharedPreferences; 22 | import android.os.AsyncTask; 23 | import android.util.Log; 24 | 25 | /** 26 | * Updates a specified SharedPreferences object on a secondary thread. 27 | */ 28 | public final class UpdatePrefsTask extends AsyncTask { 29 | private static final String TAG = "UpdatePrefsTask"; 30 | 31 | 32 | private SharedPreferences prefs; 33 | private String[] keys; 34 | 35 | public UpdatePrefsTask(SharedPreferences prefs, String... keys) { 36 | this.prefs = prefs; 37 | this.keys = keys; 38 | } 39 | 40 | @Override 41 | protected Void doInBackground(Object... params) { 42 | try { 43 | SharedPreferences.Editor editor = prefs.edit(); 44 | 45 | for (int i = 0; i < keys.length; i++) { 46 | Object value = params[i]; 47 | 48 | if (value instanceof Integer) 49 | editor.putInt(keys[i], (Integer) value); 50 | else if (value instanceof String) 51 | editor.putString(keys[i], (String) value); 52 | else if (value instanceof Float) 53 | editor.putFloat(keys[i], (Float) value); 54 | else if (value instanceof Long) 55 | editor.putLong(keys[i], (Long) value); 56 | else if (value instanceof Boolean) 57 | editor.putBoolean(keys[i], (Boolean) value); 58 | else 59 | Log.e(TAG, "The parameter type was not handled. (" + value.getClass().getName() + ")"); 60 | } 61 | 62 | editor.commit(); 63 | } 64 | catch (Exception e) { 65 | e.printStackTrace(); 66 | } 67 | return null; 68 | } 69 | } -------------------------------------------------------------------------------- /elygo-lib/src/main/java/lrstudios/games/ego/lib/themes/DarkBoardTheme.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Elygo-lib. 3 | * Copyright (C) 2012 Emmanuel Mathis [emmanuel *at* lr-studios.net] 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | package lrstudios.games.ego.lib.themes; 20 | 21 | import android.content.Context; 22 | import android.graphics.BitmapFactory; 23 | import android.graphics.BitmapShader; 24 | import android.graphics.Paint; 25 | import android.graphics.Shader; 26 | 27 | import lrstudios.games.ego.lib.R; 28 | 29 | 30 | public class DarkBoardTheme extends StandardTheme { 31 | public DarkBoardTheme(Context context) { 32 | super(context); 33 | } 34 | 35 | @Override 36 | protected void defineBackgroundPaint(Paint backgroundPaint) { 37 | backgroundPaint.setShader(new BitmapShader( 38 | BitmapFactory.decodeResource(_context.getResources(), R.drawable.wood2), 39 | Shader.TileMode.MIRROR, Shader.TileMode.MIRROR)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /elygo-lib/src/main/java/lrstudios/games/ego/lib/ui/Preferences.java: -------------------------------------------------------------------------------- 1 | package lrstudios.games.ego.lib.ui; 2 | 3 | import android.os.Bundle; 4 | import android.preference.PreferenceActivity; 5 | 6 | import lrstudios.games.ego.lib.R; 7 | 8 | 9 | public class Preferences extends PreferenceActivity { 10 | @SuppressWarnings("deprecation") 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | addPreferencesFromResource(R.xml.preferences); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /elygo-lib/src/main/java/lrstudios/games/ego/lib/util/GoUtils.java: -------------------------------------------------------------------------------- 1 | package lrstudios.games.ego.lib.util; 2 | 3 | 4 | public class GoUtils { 5 | private static final String BOARD_LETTERS = "ABCDEFGHJKLMNOPQRSTUVWXYZ"; 6 | 7 | /** 8 | * Returns the characters representing the specified X coordinate (0 = A, 1 = B, ...). 9 | * The character 'I' isn't used. 10 | */ 11 | public static String getCoordinateChars(int x) { 12 | int max = BOARD_LETTERS.length(); 13 | int firstCharIndex = Math.min(max, x / max) - 1; 14 | int secondCharIndex = x % max; 15 | 16 | if (firstCharIndex >= 0) 17 | return Character.toString(BOARD_LETTERS.charAt(firstCharIndex)) + BOARD_LETTERS.charAt(secondCharIndex); 18 | else 19 | return Character.toString(BOARD_LETTERS.charAt(secondCharIndex)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /elygo-lib/src/main/java/lrstudios/games/ego/lib/util/SoundHelper.java: -------------------------------------------------------------------------------- 1 | package lrstudios.games.ego.lib.util; 2 | 3 | import android.content.Context; 4 | import android.media.AudioManager; 5 | import android.media.SoundPool; 6 | 7 | import lrstudios.games.ego.lib.R; 8 | 9 | 10 | public class SoundHelper { 11 | private static final String TAG = SoundHelper.class.getSimpleName(); 12 | 13 | private static final int MAX_STREAMS = 4; 14 | 15 | private Context _context; 16 | private SoundPool _soundPool; 17 | private boolean _enabled = true; 18 | 19 | private int _sound_stone; 20 | private int _sound_pass; 21 | 22 | 23 | public SoundHelper(Context context) { 24 | _context = context; 25 | 26 | _soundPool = new SoundPool(MAX_STREAMS, AudioManager.STREAM_MUSIC, 0); 27 | _sound_stone = _soundPool.load(context, R.raw.stone, 1); 28 | _sound_pass = _soundPool.load(context, R.raw.pass, 1); 29 | } 30 | 31 | public void release() { 32 | _soundPool.release(); 33 | _soundPool = null; 34 | } 35 | 36 | public void playStoneSound() { 37 | playSound(_sound_stone); 38 | } 39 | 40 | public void playPassSound() { 41 | playSound(_sound_pass); 42 | } 43 | 44 | public void setSoundsEnabled(boolean enable) { 45 | _enabled = enable; 46 | } 47 | 48 | private void playSound(int soundId) { 49 | if (_enabled && _soundPool != null) 50 | _soundPool.play(soundId, 0.99f, 0.99f, 0, 0, 1.0f); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /elygo-lib/src/main/java/lrstudios/util/Rect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Elygo-lib. 3 | * Copyright (C) 2012 Emmanuel Mathis [emmanuel *at* lr-studios.net] 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | package lrstudios.util; 20 | 21 | 22 | public final class Rect { 23 | public int top; 24 | public int left; 25 | public int bottom; 26 | public int right; 27 | 28 | 29 | /** 30 | * Creates a new rectangle with the coordinates set to 0. 31 | */ 32 | public Rect() { 33 | } 34 | 35 | /** 36 | * Creates a new rectangle with the specified coordinates. 37 | */ 38 | public Rect(int left, int top, int right, int bottom) { 39 | this.left = left; 40 | this.top = top; 41 | this.right = right; 42 | this.bottom = bottom; 43 | } 44 | 45 | 46 | /** 47 | * Returns true if (x,y) is inside the Rectangle. Both left, top, bottom, right are considered to be inside. 48 | */ 49 | public boolean contains(int x, int y) { 50 | return (x >= left && x <= right && y >= top && y <= bottom); 51 | } 52 | 53 | 54 | @Override 55 | public String toString() { 56 | return "[Rect] top=" + top + ", left=" + left + ", bottom=" + bottom + ", right=" + right; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /elygo-lib/src/main/java/lrstudios/util/io/BitReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Elygo-lib. 3 | * Copyright (C) 2012 Emmanuel Mathis [emmanuel *at* lr-studios.net] 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | package lrstudios.util.io; 20 | 21 | import java.io.EOFException; 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | 25 | 26 | /** 27 | * Reads bits from an InputStream. 28 | */ 29 | public class BitReader { 30 | private InputStream _stream; 31 | private byte[] _buffer; 32 | private int _bufferPos; 33 | private int _bitmask; 34 | 35 | 36 | public BitReader(InputStream stream) { 37 | _stream = stream; 38 | _buffer = new byte[128]; 39 | _bufferPos = _buffer.length; 40 | _bitmask = 0x1; 41 | } 42 | 43 | /** 44 | * Reads a single byte from the underlying stream. 45 | * 46 | * @throws IOException An error occured during reading, or the end of stream has been reached. 47 | */ 48 | public boolean read() throws IOException { 49 | if (_bufferPos == _buffer.length) { 50 | int bytesRead = _stream.read(_buffer); 51 | if (bytesRead < 0) 52 | throw new EOFException(); 53 | 54 | _bufferPos = _buffer.length - bytesRead; 55 | System.arraycopy(_buffer, 0, _buffer, _bufferPos, bytesRead); 56 | } 57 | 58 | boolean bit = (_buffer[_bufferPos] & _bitmask) != 0; 59 | 60 | if (_bitmask == 0x80) { 61 | _bitmask = 0x1; 62 | _bufferPos++; 63 | } 64 | else { 65 | _bitmask <<= 1; 66 | } 67 | 68 | return bit; 69 | } 70 | 71 | 72 | /** 73 | * Reads multiple bytes from the underlying stream and returns them in a long (byte order is 74 | * preserved : highest bytes in the stream will remain the highest bytes in the returned long). 75 | * 76 | * @param bitsToRead The number of bits to read, between 1 and 64 (included). 77 | * @throws IOException An error occured during reading, or the end of stream has been reached. 78 | */ 79 | public long read(int bitsToRead) throws IOException { 80 | if (bitsToRead > 64) 81 | bitsToRead = 64; 82 | 83 | long result = 0; 84 | for (int i = bitsToRead - 1; i >= 0; i--) { 85 | if (read()) 86 | result |= 1 << i; 87 | } 88 | 89 | return result; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/anim/fragment_fade_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/anim/fragment_fade_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-mdpi/list_extra_button_left_border.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-mdpi/list_extra_button_left_border.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-nodpi/actionbar_top_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-nodpi/actionbar_top_bg.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-nodpi/login_frame.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-nodpi/login_frame.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-nodpi/wood2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-nodpi/wood2.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-nodpi/wood6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-nodpi/wood6.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/__btn_default_disabled_focused_holo_light.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/__btn_default_disabled_focused_holo_light.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/__btn_default_disabled_holo_light.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/__btn_default_disabled_holo_light.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/__btn_default_focused_holo_light.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/__btn_default_focused_holo_light.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/__btn_default_normal_holo_light.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/__btn_default_normal_holo_light.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/__btn_default_pressed_holo_light.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/__btn_default_pressed_holo_light.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/__btn_green_normal_holo_light.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/__btn_green_normal_holo_light.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/__btn_red_normal_holo_light.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/__btn_red_normal_holo_light.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/dialog_full_holo_light.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/dialog_full_holo_light.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/grey_background_pattern_tile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/grey_background_pattern_tile.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/grey_border_inset_lr.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/grey_border_inset_lr.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_action_help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_action_help.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_action_navigation_next_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_action_navigation_next_disabled.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_action_navigation_next_enabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_action_navigation_next_enabled.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_action_navigation_previous_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_action_navigation_previous_disabled.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_action_navigation_previous_enabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_action_navigation_previous_enabled.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_action_restart_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_action_restart_disabled.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_action_restart_enabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_action_restart_enabled.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_action_save_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_action_save_disabled.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_action_save_enabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_action_save_enabled.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_action_settings.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_action_split_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_action_split_disabled.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_action_split_enabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_action_split_enabled.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_action_undo_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_action_undo_disabled.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_action_undo_enabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_action_undo_enabled.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_green_check_mark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_green_check_mark.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/ic_red_cross.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/ic_red_cross.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/item_activated.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/item_activated.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/item_checked.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/item_checked.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/item_focused.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/item_focused.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/item_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/item_pressed.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable-xhdpi/list_extra_button_left_border.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable-xhdpi/list_extra_button_left_border.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/__btn_default_holo_light.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 33 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/__btn_green_holo_light.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 19 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/__btn_red_holo_light.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 19 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/actionbar_shadow.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/drawable/actionbar_shadow.9.png -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/activatable_grey_item_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/activatable_item_background.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/bottom_bar_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 11 | 12 | 13 | 14 | 15 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/dialog_title_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/grey_background_pattern.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 20 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/ic_action_navigation_next.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 10 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/ic_action_navigation_previous.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 10 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/ic_action_restart.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 10 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/ic_action_save.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 10 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/ic_action_split.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 10 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/ic_action_undo.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 10 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/list_extra_button_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/main_top_separator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/drawable/main_top_separator_horizontal.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/layout/activity_with_fragment_container.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/layout/board_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 16 | 17 | 21 | 22 | 26 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/layout/detailed_seek_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 16 | 17 | 24 | 25 | 31 | 32 | 39 | 40 | 47 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/layout/dialog_save_file.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 16 | 17 | 24 | 25 | 36 | 37 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/layout/toolbar_with_progress.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 16 | 17 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/menu/actionbar_gtp_board.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 15 | 21 | 27 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/raw/pass.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/raw/pass.mp3 -------------------------------------------------------------------------------- /elygo-lib/src/main/res/raw/stone.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/elygo-lib/src/main/res/raw/stone.wav -------------------------------------------------------------------------------- /elygo-lib/src/main/res/values-de/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Versetzt 5 | Versetzt (nur bei großen Brettausschnitten) 6 | Punktgenau (Stylus-Modus) 7 | 8 | 9 | 10 | Standard 11 | Holzstruktur 12 | Schwarz und Weiß 13 | 14 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/values-fr/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 (plus rapide) 4 | 2 5 | 3 6 | 4 7 | 5 8 | 6 9 | 7 10 | 8 11 | 9 12 | 10 (plus fort) 13 | 14 | 15 | 16 | Décalage (toujours) 17 | Décalage (grands goban uniquement) 18 | Mode stylet 19 | 20 | 21 | 22 | Standard 23 | Bois sombre 24 | Noir et blanc 25 | 26 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/values-ja/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1 速い 5 | 2 6 | 3 7 | 4 8 | 5 9 | 6 10 | 7 11 | 8 12 | 9 13 | 10 強い 14 | 15 | 16 | 17 | オフセット (常に) 18 | オフセット (唯19x19) 19 | スタイラスモード 20 | 21 | 22 | 23 | ウッド 24 | ダークウッド 25 | 26 | 27 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/values-ko/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 흰색 8 | 검은색 9 | 접바둑 10 | 규칙 11 | 12 | 저장 13 | 불러오기 14 | 플레이어 15 | 새로 고침 16 | 보드 크기 17 | 버전 %s 18 | 랜덤 19 | 불러오는 중... 20 | 21 | 설정 22 | 23 | 24 | Pass 25 | 취소 26 | 정보 27 | 28 | 29 | 30 | 일반 31 | 외관 32 | 소리 33 | 항상 화면 켜짐 34 | 35 | 상태 표시 줄 숨기기 36 | 37 | 입력 유형 38 | 39 | 바둑판 테마 40 | 41 | 선 두께 42 | 43 | 돌 간격 44 | 45 | 46 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 4 | 9 5 | 11 6 | 13 7 | 15 8 | 17 9 | 19 10 | 11 | 12 | 13 | 7.5 14 | 6.5 15 | 5.5 16 | 0.5 17 | -6.5 18 | 19 | 20 | 21 | 0 22 | 2 23 | 3 24 | 4 25 | 5 26 | 6 27 | 7 28 | 8 29 | 9 30 | 31 | 32 | 33 | @string/black 34 | @string/white 35 | @string/random 36 | 37 | 38 | 39 | 1 (faster) 40 | 2 41 | 3 42 | 4 43 | 5 44 | 6 45 | 7 46 | 8 47 | 9 48 | 10 (stronger) 49 | 50 | 51 | 52 | Offset (always) 53 | Offset (large boards only) 54 | Stylus mode 55 | 56 | 57 | offset 58 | offsetLarge 59 | stylus 60 | 61 | 62 | 0 63 | 1 64 | 2 65 | 3 66 | 67 | 68 | 0 69 | 1 70 | 2 71 | 3 72 | 73 | 74 | 75 | 1 76 | 2 77 | 3 78 | 4 79 | 5 80 | 81 | 82 | 1 83 | 2 84 | 3 85 | 4 86 | 5 87 | 88 | 89 | 90 | Standard 91 | Dark Wood 92 | Black & white 93 | 94 | 95 | standard 96 | darkwood 97 | blackwhite 98 | 99 | 100 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | #666666 3 | #20000000 4 | #8AE 5 | 6 | #ff33b5e5 7 | #ff99cc00 8 | #ffff4444 9 | #ff0099cc 10 | #ff669900 11 | #ffcc0000 12 | #ffaa66cc 13 | #ff9933cc 14 | #ffffbb33 15 | #ffff8800 16 | #ff00ddff 17 | 18 | #00000000 19 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 48dp 4 | 56dp 5 | 6dp 6 | 7 | 30dp 8 | 4dp 9 | 36dp 10 | 11 | 48dp 12 | 13 | 64dp 14 | 48dp 15 | 16 | 2dp 17 | -------------------------------------------------------------------------------- /elygo-lib/src/main/res/xml/preferences.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 14 | 19 | 25 | 32 | 33 | 34 | 35 | 42 | 49 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Feb 10 12:33:05 CET 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /jni/Android.mk: -------------------------------------------------------------------------------- 1 | include $(call all-subdir-makefiles) 2 | -------------------------------------------------------------------------------- /jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_PROJECT_PATH := $(call my-dir)/.. 2 | APP_MODULES := pachi 3 | APP_ABI := armeabi armeabi-v7a x86 4 | APP_OPTIM := release 5 | -------------------------------------------------------------------------------- /jni/pachi/.gitignore: -------------------------------------------------------------------------------- 1 | .deps 2 | .*.swp 3 | *.o 4 | *.a 5 | pachi 6 | tags 7 | book.dat 8 | patterns.prob 9 | patterns.spat 10 | -------------------------------------------------------------------------------- /jni/pachi/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | APP_PLATFORM := android-5 6 | LOCAL_MODULE := pachi 7 | 8 | LOCAL_LDFLAGS += -fPIE -pie 9 | LOCAL_CPP_FLAGS := -fno-exceptions -fPIE -pie 10 | LOCAL_CFLAGS := -std=c99 -fPIE -pie \ 11 | -I$(LOCAL_PATH) \ 12 | -I$(LOCAL_PATH)/joseki \ 13 | -I$(LOCAL_PATH)/distributed \ 14 | -I$(LOCAL_PATH)/playout \ 15 | -I$(LOCAL_PATH)/montecarlo \ 16 | -I$(LOCAL_PATH)/random \ 17 | -I$(LOCAL_PATH)/patternplay \ 18 | -I$(LOCAL_PATH)/patternscan \ 19 | -I$(LOCAL_PATH)/replay \ 20 | -I$(LOCAL_PATH)/tactics \ 21 | -I$(LOCAL_PATH)/uct \ 22 | -I$(LOCAL_PATH)/uct/policy 23 | 24 | LOCAL_SRC_FILES := \ 25 | \ 26 | android/util.c \ 27 | fbook.c \ 28 | board.c \ 29 | network.c \ 30 | gtp.c \ 31 | chat.c \ 32 | move.c \ 33 | ownermap.c \ 34 | pachi.c \ 35 | pattern.c \ 36 | pattern3.c \ 37 | patternprob.c \ 38 | patternsp.c \ 39 | playout.c \ 40 | probdist.c \ 41 | random.c \ 42 | stone.c \ 43 | timeinfo.c \ 44 | t-unit/test.c \ 45 | montecarlo/montecarlo.c \ 46 | joseki/base.c \ 47 | joseki/joseki.c \ 48 | distributed/distributed.c \ 49 | distributed/merge.c \ 50 | distributed/protocol.c \ 51 | patternplay/patternplay.c \ 52 | patternscan/patternscan.c \ 53 | playout/light.c \ 54 | playout/moggy.c \ 55 | random/random.c \ 56 | replay/replay.c \ 57 | tactics/1lib.c \ 58 | tactics/2lib.c \ 59 | tactics/ladder.c \ 60 | tactics/nakade.c \ 61 | tactics/nlib.c \ 62 | tactics/selfatari.c \ 63 | tactics/util.c \ 64 | uct/policy/generic.c \ 65 | uct/policy/ucb1.c \ 66 | uct/policy/ucb1amaf.c \ 67 | uct/dynkomi.c \ 68 | uct/plugins.c \ 69 | uct/prior.c \ 70 | uct/search.c \ 71 | uct/slave.c \ 72 | uct/tree.c \ 73 | uct/uct.c \ 74 | uct/walk.c \ 75 | #uct/plugin/example.c \ 76 | #uct/plugin/wolf.c \ 77 | 78 | include $(BUILD_EXECUTABLE) 79 | -------------------------------------------------------------------------------- /jni/pachi/CREDITS: -------------------------------------------------------------------------------- 1 | Pachi stands on research shoulders of giants, specifically: 2 | 3 | Modification of UCT with Patterns in Monte-Carlo Go 4 | Sylvain Gelly, Yizao Wang, Remi Munos & Olivier Teytaud 5 | 6 | Combining Online and Offline Knowledge in UCT 7 | Sylvain Gelly, David Silver 8 | 9 | 10 | Pachi contains unpublished methods we claim we have invented 11 | independently and are preparing for publication: 12 | 13 | * The dynamic komi feature. 14 | * The local tree feature. 15 | 16 | 17 | These people have made significant contributions to the code: 18 | 19 | Petr Baudis 20 | Pachi the Bot ;-) 21 | 22 | Jean-loup Gaily 23 | Distributed engine 24 | Time allocation algorithm 25 | Efficient UCT memory allocator 26 | 27 | 28 | Pachi uses data extracted from the Kogo joseki dictionary as its 29 | joseki database: http://waterfire.us/joseki.htm 30 | -------------------------------------------------------------------------------- /jni/pachi/TODO: -------------------------------------------------------------------------------- 1 | Docs: 2 | * Manual page - full usage documentation 3 | * GTP interface documentation 4 | 5 | Base: 6 | * Further optimize board implementation, oprofile fun 7 | * Clean up GTP interface, allow custom GTP commands for modules 8 | * Implement parameter setup over GTP 9 | * gogui-friendly GTP interface 10 | 11 | General improvements: 12 | * Opening book 13 | * Killer moves 14 | * MM local-based patterns 15 | * Balanced local-based patterns? 16 | * Local tree forcing 17 | * Liberty maps 18 | * Reverse status learning 19 | Run on game corpus. Start at final position, watch development 20 | of status of all stones. The moment the final status and expected 21 | status changes, analyze, especially if move choice differs. Use 22 | learnt status-fixing moves in simulations somehow. 23 | 24 | Playouts: 25 | * Split playout aspects to custom-stackable pieces 26 | * Possibly replay top-rated unplayed moves from the tree 27 | in the playout? 28 | 29 | UCB1AMAF: 30 | * Fix RAVE for good (still noticeably weaker than fuego?) 31 | * Separate constants for prior and amaf elements? 32 | -------------------------------------------------------------------------------- /jni/pachi/android/util.c: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | 3 | 4 | char * 5 | stpcpy(char *dest, const char *src) 6 | { 7 | register char *d = dest; 8 | register const char *s = src; 9 | 10 | do 11 | *d++ = *s; 12 | while (*s++ != '\0'); 13 | 14 | return d - 1; 15 | } 16 | -------------------------------------------------------------------------------- /jni/pachi/android/util.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_ANDROID_UTIL_H 2 | #define PACHI_ANDROID_UTIL_H 3 | 4 | // The function "stpcpy" doesn't exist in the Android NDK (version r8b) 5 | char* stpcpy(char *dest, const char *src); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /jni/pachi/book.dat.bad: -------------------------------------------------------------------------------- 1 | 9 E5 E3 C4 G3 | E7 2 | -------------------------------------------------------------------------------- /jni/pachi/book.dat.extra: -------------------------------------------------------------------------------- 1 | 9 E5 E7 G6 | E3 2 | 9 E5 E7 G6 E3 | C6 3 | 9 E5 E7 G6 E3 C6 | C7 4 | 9 E5 E7 G6 E3 C6 C7 | D3 5 | 9 E5 E7 G6 E3 C6 C7 D3 | D2 6 | 9 E5 E7 G6 E3 C6 C7 D3 D2 | D4 7 | 9 E5 E7 G6 E3 C6 C7 D3 D2 D4 | G4 8 | 9 E5 E7 G6 E3 C6 C7 D3 D2 D4 D6 | C5 9 | 9 E5 E7 G6 E3 C6 C7 D3 D2 D4 D6 C5 | G3 10 | 9 E5 E7 G6 E3 C6 C7 D3 D2 D4 D6 C5 G3 | F8 11 | 9 E5 E7 G6 E3 C6 C7 D3 D2 D4 D6 C5 G3 F8 | B6 12 | 9 E5 E7 G6 E3 C6 C7 D3 D2 D4 D6 C5 G3 F8 B6 | C2 13 | 9 E5 E7 G6 E3 C6 C7 D3 D2 D4 D6 C5 G3 F8 B6 C2 | E2 14 | 9 E5 E7 G6 E3 C6 C7 D3 D2 D4 D6 C5 G3 F8 B6 C2 E2 | E8 15 | 9 E5 E7 G6 E3 C4 | C3 16 | 9 E5 E7 G6 E3 C4 C3 | D4 17 | 9 E5 E7 G6 E3 C4 C3 D4 | D3 18 | 9 E5 E7 G6 E3 C4 C3 D4 D3 | C7 19 | 9 E5 E7 G6 E3 C4 C3 D4 D3 C7 | F6 20 | 9 E5 E7 G6 E3 C4 C3 D4 D3 C7 F6 | F5 21 | 9 E5 E7 G6 E3 C4 C3 D4 D3 C7 F6 F5 | G7 22 | 9 E5 E7 G6 E3 C4 C3 D4 D3 C7 F6 F5 G7 | G3 23 | 9 E5 E7 G5 | E3 24 | 9 E5 E7 G5 E3 | C5 25 | 9 E5 E7 G5 E3 C5 | C7 26 | 9 E5 E7 G5 E3 C5 C7 | C3 27 | 9 E5 E7 G5 E3 C5 C7 C3 | G3 28 | 9 E5 E7 G5 E3 C5 C7 C3 G3 | G7 29 | 9 E5 E7 G6 C6 | C4 30 | 9 E5 G5 | E3 31 | -------------------------------------------------------------------------------- /jni/pachi/chat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define DEBUG 8 | 9 | #include "debug.h" 10 | #include "chat.h" 11 | #include "random.h" 12 | 13 | #define MAX_CHAT_PATTERNS 500 14 | 15 | static struct chat { 16 | double minwin; 17 | double maxwin; 18 | char from[20]; 19 | char regex[100]; 20 | char reply[300]; // in printf format with one param (100*winrate) 21 | 22 | bool displayed; 23 | bool match; 24 | } *chat_table; 25 | 26 | static char default_reply[] = "I know all those words, but that sentence makes no sense to me"; 27 | static char not_playing[] = "I'm winning big without playing"; 28 | 29 | /* Read the chat file, a sequence of lines of the form: 30 | * minwin;maxwin;from;regex;reply 31 | * Set minwin, maxwin to -1.0 2.0 for answers to chat other than winrate. 32 | * Set from as one space for replies to anyone. 33 | * Examples: 34 | * -1.0;0.3; ;winrate;%.1f%% I'm losing 35 | * -1.0;2.0;pasky;^when ;Today 36 | */ 37 | void chat_init(char *chat_file) { 38 | } 39 | 40 | void chat_done() { 41 | } 42 | 43 | /* Reply to a chat. When not playing, color is S_NONE and all remaining parameters are undefined. 44 | * If some matching entries have not yet been displayed we pick randomly among them. Otherwise 45 | * we pick randomly among all matching entries. */ 46 | char 47 | *generic_chat(struct board *b, bool opponent, char *from, char *cmd, enum stone color, coord_t move, 48 | int playouts, int machines, int threads, double winrate, double extra_komi) { 49 | return NULL; 50 | } 51 | -------------------------------------------------------------------------------- /jni/pachi/chat.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_CHAT_H 2 | #define PACHI_CHAT_H 3 | 4 | #include 5 | 6 | #include "stone.h" 7 | #include "move.h" 8 | 9 | struct board; 10 | 11 | void chat_init(char *chat_file); 12 | void chat_done(); 13 | 14 | char *generic_chat(struct board *b, bool opponent, char *from, char *cmd, enum stone color, coord_t move, 15 | int playouts, int machines, int threads, double winrate, double extra_komi); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /jni/pachi/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_DEBUG_H 2 | #define PACHI_DEBUG_H 3 | 4 | #include 5 | 6 | #ifdef DEBUG 7 | #define DEBUGL_(l, n) (unlikely((l) > (n))) 8 | #define DEBUG_MODE (true) 9 | #else 10 | #define DEBUGL_(l, n) (false) 11 | #define DEBUG_MODE (false) 12 | #endif 13 | 14 | extern int debug_level; 15 | extern bool debug_boardprint; 16 | 17 | #define DEBUGL(n) DEBUGL_(debug_level, n) 18 | 19 | /* The distributed engine can be _very_ verbose so use DEBUGV 20 | * to keep only the first N verbose logs. */ 21 | #ifndef MAX_VERBOSE_LOGS 22 | # define MAX_VERBOSE_LOGS 100000 23 | #endif 24 | extern long verbose_logs; 25 | #define DEBUGV(verbose, n) (DEBUGL(n) && (!(verbose) || ++verbose_logs < MAX_VERBOSE_LOGS)) 26 | #define DEBUGVV(n) DEBUGV(true, (n)) 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /jni/pachi/distributed/Makefile: -------------------------------------------------------------------------------- 1 | INCLUDES=-I.. 2 | OBJS=distributed.o protocol.o merge.o 3 | 4 | all: distributed.a 5 | distributed.a: $(OBJS) 6 | 7 | clean: 8 | rm -f *.o *.a 9 | clean-profiled: 10 | rm -f *.gcda *.gcno 11 | 12 | -include ../Makefile.lib 13 | -------------------------------------------------------------------------------- /jni/pachi/distributed/merge.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_DISTRIBUTED_MERGE_H 2 | #define PACHI_DISTRIBUTED_MERGE_H 3 | 4 | #include "distributed/protocol.h" 5 | 6 | void merge_print_stats(int total_hnodes); 7 | void merge_init(struct slave_state *sstate, int shared_nodes, int stats_hbits, int max_slaves); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /jni/pachi/distributed/protocol.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_DISTRIBUTED_PROTOCOL_H 2 | #define PACHI_DISTRIBUTED_PROTOCOL_H 3 | 4 | #ifdef _WIN32 5 | #include 6 | #include 7 | #else 8 | #include 9 | #include 10 | #endif 11 | 12 | #include "board.h" 13 | 14 | 15 | /* Each slave thread maintains a ring of 256 buffers holding 16 | * incremental stats received from the slave. The oldest 17 | * buffer is recycled to hold stats sent to the slave and 18 | * received the next reply. */ 19 | #define BUFFERS_PER_SLAVE_BITS 8 20 | #define BUFFERS_PER_SLAVE (1 << BUFFERS_PER_SLAVE_BITS) 21 | 22 | struct slave_state; 23 | typedef void (*buffer_hook)(void *buf, int size); 24 | typedef void (*state_alloc_hook)(struct slave_state *sstate); 25 | typedef int (*getargs_hook)(void *buf, struct slave_state *sstate, int cmd_id); 26 | 27 | struct buf_state { 28 | void *buf; 29 | /* All buffers have the same physical size. size is the 30 | * number of valid bytes. It is set only when the buffer 31 | * is actually in the receive queueue. */ 32 | int size; 33 | int queue_index; 34 | int owner; 35 | }; 36 | 37 | struct slave_state { 38 | int max_buf_size; 39 | int thread_id; 40 | struct in_addr client; // for debugging only 41 | state_alloc_hook alloc_hook; 42 | buffer_hook insert_hook; 43 | getargs_hook args_hook; 44 | 45 | /* Index in received_queue of most recent processed 46 | * buffer, -1 if none processed yet. */ 47 | int last_processed; 48 | 49 | /* --- PRIVATE DATA for protocol.c --- */ 50 | 51 | struct buf_state b[BUFFERS_PER_SLAVE]; 52 | int newest_buf; 53 | int slave_sock; 54 | 55 | /* --- PRIVATE DATA for merge.c --- */ 56 | 57 | /* Hash table of incremental stats. */ 58 | struct incr_stats *stats_htable; 59 | int stats_hbits; 60 | int stats_id; 61 | 62 | /* Hash indices updated by stats merge. */ 63 | int *merged; 64 | int max_merged_nodes; 65 | }; 66 | extern struct slave_state default_sstate; 67 | 68 | void protocol_lock(void); 69 | void protocol_unlock(void); 70 | 71 | void logline(struct in_addr *client, char *prefix, char *s); 72 | 73 | void clear_receive_queue(void); 74 | void update_cmd(struct board *b, char *cmd, char *args, bool new_id); 75 | void new_cmd(struct board *b, char *cmd, char *args); 76 | void get_replies(double time_limit, int min_replies); 77 | void protocol_init(char *slave_port, char *proxy_port, int max_slaves); 78 | 79 | extern int reply_count; 80 | extern char **gtp_replies; 81 | extern int active_slaves; 82 | 83 | /* All binary buffers received from all slaves in current move are in 84 | * receive_queue[0..queue_length-1] */ 85 | extern struct buf_state **receive_queue; 86 | extern int queue_length; 87 | /* Queue age is incremented each time the queue is emptied. */ 88 | extern int queue_age; 89 | 90 | /* Max size of all gtp commands for one game. 91 | * 60 chars for the first line of genmoves plus 100 lines 92 | * of 30 chars each for the stats at last move. */ 93 | #define CMDS_SIZE (60*MAX_GAMELEN + 30*100) 94 | 95 | /* Max size for one line of reply or slave log. */ 96 | #define BSIZE 4096 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /jni/pachi/engine.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_ENGINE_H 2 | #define PACHI_ENGINE_H 3 | 4 | #include "board.h" 5 | #include "move.h" 6 | #include "gtp.h" 7 | 8 | struct move_queue; 9 | 10 | typedef enum parse_code (*engine_notify)(struct engine *e, struct board *b, int id, char *cmd, char *args, char **reply); 11 | typedef char *(*engine_notify_play)(struct engine *e, struct board *b, struct move *m, char *enginearg); 12 | typedef char *(*engine_undo)(struct engine *e, struct board *b); 13 | typedef char *(*engine_result)(struct engine *e, struct board *b); 14 | typedef char *(*engine_chat)(struct engine *e, struct board *b, bool in_game, char *from, char *cmd); 15 | /* Generate a move. If pass_all_alive is true, shall be generated only 16 | * if all stones on the board can be considered alive, without regard to "dead" 17 | * considered stones. */ 18 | typedef coord_t *(*engine_genmove)(struct engine *e, struct board *b, struct time_info *ti, enum stone color, bool pass_all_alive); 19 | typedef char *(*engine_genmoves)(struct engine *e, struct board *b, struct time_info *ti, enum stone color, 20 | char *args, bool pass_all_alive, void **stats_buf, int *stats_size); 21 | /* Evaluate feasibility of player @color playing at all free moves. Will 22 | * simulate each move from b->f[i] for time @ti, then set 23 | * 1-max(opponent_win_likelihood) in vals[i]. */ 24 | typedef void (*engine_evaluate)(struct engine *e, struct board *b, struct time_info *ti, floating_t *vals, enum stone color); 25 | /* One dead group per queued move (coord_t is (ab)used as group_t). */ 26 | typedef void (*engine_dead_group_list)(struct engine *e, struct board *b, struct move_queue *mq); 27 | /* e->data and e will be free()d by caller afterwards. */ 28 | typedef void (*engine_done)(struct engine *e); 29 | 30 | /* This is engine data structure. A new engine instance is spawned 31 | * for each new game during the program lifetime. */ 32 | struct engine { 33 | char *name; 34 | char *comment; 35 | 36 | /* If set, do not reset the engine state on clear_board. */ 37 | bool keep_on_clear; 38 | 39 | engine_notify notify; 40 | board_cprint printhook; 41 | engine_notify_play notify_play; 42 | engine_chat chat; 43 | engine_undo undo; 44 | engine_result result; 45 | engine_genmove genmove; 46 | engine_genmoves genmoves; 47 | engine_evaluate evaluate; 48 | engine_dead_group_list dead_group_list; 49 | engine_done done; 50 | void *data; 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /jni/pachi/fbook.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_FBOOK_H 2 | #define PACHI_FBOOK_H 3 | 4 | #include "move.h" 5 | 6 | struct board; 7 | 8 | /* Opening book (fbook as in "forcing book" since the move is just 9 | * played unconditionally if found, or possibly "fuseki book"). */ 10 | 11 | struct fbook { 12 | int bsize; 13 | int handicap; 14 | 15 | int movecnt; 16 | 17 | #define fbook_hash_bits 20 // 12M w/ 32-bit coord_t 18 | #define fbook_hash_mask ((1 << fbook_hash_bits) - 1) 19 | /* pass == no move in this position */ 20 | coord_t moves[1< 10 | 11 | typedef uint_fast32_t fixp_t; 12 | 13 | /* We should accomodate at least 0..131072 (17bits) in the whole number 14 | * portion; assuming at least 32bit integer, that leaves us with 15-bit 15 | * fractional part. Thankfully, we need only unsigned values. */ 16 | #define FIXP_BITS 15 17 | 18 | #define FIXP_SCALE (1<kogo.sgf 31 | perl joseki/sgfvar2gtp.pl kogo.sgf >kogo.gtp 32 | cat kogo.gtp | ./pachi -e joseki -d 0 | grep -v ^= | grep -v '^$' >joseki19.pdict 33 | -------------------------------------------------------------------------------- /jni/pachi/joseki/base.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define DEBUG 6 | #include "board.h" 7 | #include "debug.h" 8 | #include "move.h" 9 | #include "joseki/base.h" 10 | 11 | 12 | struct joseki_dict * 13 | joseki_init(int bsize) 14 | { 15 | struct joseki_dict *jd = calloc(1, sizeof(*jd)); 16 | jd->bsize = bsize; 17 | jd->patterns = calloc(1 << joseki_hash_bits, sizeof(jd->patterns[0])); 18 | return jd; 19 | } 20 | 21 | struct joseki_dict * 22 | joseki_load(int bsize) 23 | { 24 | char fname[1024]; 25 | snprintf(fname, 1024, "joseki%d.pdict", bsize - 2); 26 | FILE *f = fopen(fname, "r"); 27 | if (!f) { 28 | if (DEBUGL(3)) 29 | perror(fname); 30 | return NULL; 31 | } 32 | struct joseki_dict *jd = joseki_init(bsize); 33 | 34 | char linebuf[1024]; 35 | while (fgets(linebuf, 1024, f)) { 36 | char *line = linebuf; 37 | 38 | while (isspace(*line)) line++; 39 | if (*line == '#') 40 | continue; 41 | hash_t h = strtoull(line, &line, 16); 42 | while (isspace(*line)) line++; 43 | enum stone color = *line++ == 'b' ? S_BLACK : S_WHITE; 44 | while (isspace(*line)) line++; 45 | 46 | /* Get count. */ 47 | char *cs = strrchr(line, ' '); assert(cs); 48 | *cs++ = 0; 49 | int count = atoi(cs); 50 | 51 | coord_t **ccp = &jd->patterns[h].moves[color - 1]; 52 | assert(!*ccp); 53 | *ccp = calloc2(count + 1, sizeof(coord_t)); 54 | coord_t *cc = *ccp; 55 | while (*line) { 56 | assert(cc - *ccp < count); 57 | coord_t *c = str2coord(line, bsize); 58 | *cc++ = *c; 59 | coord_done(c); 60 | line += strcspn(line, " "); 61 | line += strspn(line, " "); 62 | } 63 | *cc = pass; 64 | } 65 | 66 | fclose(f); 67 | if (DEBUGL(2)) 68 | fprintf(stderr, "Joseki dictionary for board size %d loaded.\n", bsize - 2); 69 | return jd; 70 | } 71 | 72 | void 73 | joseki_done(struct joseki_dict *jd) 74 | { 75 | if (!jd) return; 76 | free(jd->patterns); 77 | free(jd); 78 | } 79 | -------------------------------------------------------------------------------- /jni/pachi/joseki/base.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_JOSEKI_BASE_H 2 | #define PACHI_JOSEKI_BASE_H 3 | 4 | #include "board.h" 5 | 6 | /* Single joseki situation - moves for S_BLACK-1, S_WHITE-1. */ 7 | struct joseki_pattern { 8 | /* moves[] is a pass-terminated list or NULL */ 9 | coord_t *moves[2]; 10 | }; 11 | 12 | /* The joseki dictionary for given board size. */ 13 | struct joseki_dict { 14 | int bsize; 15 | 16 | #define joseki_hash_bits 20 // 8M w/ 32-bit pointers 17 | #define joseki_hash_mask ((1 << joseki_hash_bits) - 1) 18 | struct joseki_pattern *patterns; 19 | }; 20 | 21 | struct joseki_dict *joseki_init(int bsize); 22 | struct joseki_dict *joseki_load(int bsize); 23 | void joseki_done(struct joseki_dict *); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /jni/pachi/joseki/joseki.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_JOSEKI_JOSEKI_H 2 | #define PACHI_JOSEKI_JOSEKI_H 3 | 4 | #include "engine.h" 5 | 6 | struct engine *engine_joseki_init(char *arg, struct board *b); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /jni/pachi/joseki/sgfvar2gtp.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # Convert SGF file to a sequence of GTP games, one game per each variation 3 | # that ends with /GOOD/ comment. 4 | 5 | use warnings; 6 | use strict; 7 | 8 | sub printgame 9 | { 10 | my ($sgf) = @_; 11 | my $pt = $sgf->getAddress(); 12 | 13 | my @moves; 14 | do { 15 | my ($b, $w) = ($sgf->property('B'), $sgf->property('W')); 16 | if ($b) { push @moves, ['b', $_] foreach @$b; } 17 | if ($w) { push @moves, ['w', $_] foreach @$w; } 18 | } while ($sgf->prev()); 19 | 20 | print "boardsize 19\nclear_board\n"; 21 | for my $move (reverse @moves) { 22 | my ($sx, $sy) = @{$move->[1]}; 23 | my @abcd = split(//, "abcdefghjklmnopqrstuvwxyz"); 24 | my $x = $sy + 1; my $y = $abcd[18 - $sx]; 25 | if ("$y$x" eq "z20") { 26 | $y = "pass"; $x = ""; 27 | } 28 | print "play ".$move->[0]." $y$x\n"; 29 | } 30 | 31 | $sgf->goto($pt); 32 | } 33 | 34 | sub recurse 35 | { 36 | my ($sgf) = @_; 37 | my $c = $sgf->property('C'); 38 | if ($c and $c->[0] =~ /GOOD/) { 39 | printgame($sgf); 40 | } 41 | for (0 .. $sgf->branches()-1) { 42 | $sgf->gotoBranch($_); 43 | recurse($sgf); 44 | $sgf->prev(); 45 | } 46 | } 47 | 48 | use Games::SGF::Go; 49 | my $sgf = new Games::SGF::Go; 50 | 51 | $sgf->readFile($ARGV[0]); 52 | 53 | $sgf->gotoRoot(); 54 | recurse($sgf); 55 | -------------------------------------------------------------------------------- /jni/pachi/media/pachi-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/jni/pachi/media/pachi-small.png -------------------------------------------------------------------------------- /jni/pachi/media/pachi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emathis11/android-pachi/4d79cae0568776ba2ea3a05bb370fd60953e6581/jni/pachi/media/pachi.jpg -------------------------------------------------------------------------------- /jni/pachi/montecarlo/Makefile: -------------------------------------------------------------------------------- 1 | INCLUDES=-I.. 2 | OBJS=montecarlo.o 3 | 4 | all: montecarlo.a 5 | montecarlo.a: $(OBJS) 6 | 7 | clean: 8 | rm -f *.o *.a 9 | clean-profiled: 10 | rm -f *.gcda *.gcno 11 | 12 | -include ../Makefile.lib 13 | -------------------------------------------------------------------------------- /jni/pachi/montecarlo/internal.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_MONTECARLO_INTERNAL_H 2 | #define PACHI_MONTECARLO_INTERNAL_H 3 | 4 | #include "debug.h" 5 | #include "move.h" 6 | 7 | struct playout_policy; 8 | 9 | /* Internal MonteCarlo structures */ 10 | 11 | 12 | /* Internal engine state. */ 13 | struct montecarlo { 14 | int debug_level; 15 | int gamelen; 16 | floating_t resign_ratio; 17 | int loss_threshold; 18 | struct playout_policy *playout; 19 | }; 20 | 21 | #define MCDEBUGL(n) DEBUGL_(mc->debug_level, n) 22 | 23 | 24 | /* Per-move playout statistics. */ 25 | struct move_stat { 26 | int games; 27 | int wins; 28 | }; 29 | 30 | void board_stats_print(struct board *board, struct move_stat *moves, FILE *f); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /jni/pachi/montecarlo/montecarlo.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_MONTECARLO_MONTECARLO_H 2 | #define PACHI_MONTECARLO_MONTECARLO_H 3 | 4 | #include "engine.h" 5 | 6 | struct engine *engine_montecarlo_init(char *arg, struct board *b); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /jni/pachi/move.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "board.h" 7 | #include "move.h" 8 | 9 | 10 | /* The S_OFFBOARD margin is not addressable by coordinates. */ 11 | 12 | static char asdf[] = "abcdefghjklmnopqrstuvwxyz"; 13 | 14 | char * 15 | coord2bstr(char *buf, coord_t c, struct board *board) 16 | { 17 | if (is_pass(c)) { 18 | return "pass"; 19 | } else if (is_resign(c)) { 20 | return "resign"; 21 | } else { 22 | /* Some GTP servers are broken and won't grok lowercase coords */ 23 | snprintf(buf, 4, "%c%d", toupper(asdf[coord_x(c, board) - 1]), coord_y(c, board)); 24 | return buf; 25 | } 26 | } 27 | 28 | /* Return coordinate in dynamically allocated buffer. */ 29 | char * 30 | coord2str(coord_t c, struct board *board) 31 | { 32 | char buf[256]; 33 | return strdup(coord2bstr(buf, c, board)); 34 | } 35 | 36 | /* Return coordinate in statically allocated buffer, with some backlog for 37 | * multiple independent invocations. Useful for debugging. */ 38 | char * 39 | coord2sstr(coord_t c, struct board *board) 40 | { 41 | static char *b; 42 | static char bl[10][4]; 43 | static int bi; 44 | b = bl[bi]; bi = (bi + 1) % 10; 45 | return coord2bstr(b, c, board); 46 | } 47 | 48 | /* No sanity checking */ 49 | coord_t * 50 | str2coord(char *str, int size) 51 | { 52 | if (!strcasecmp(str, "pass")) { 53 | return coord_pass(); 54 | } else if (!strcasecmp(str, "resign")) { 55 | return coord_resign(); 56 | } else { 57 | char xc = tolower(str[0]); 58 | return coord_init(xc - 'a' - (xc > 'i') + 1, atoi(str + 1), size); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /jni/pachi/mq.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_MQ_H 2 | #define PACHI_MQ_H 3 | 4 | /* Move queues; in fact, they are more like move lists, usually used 5 | * to accumulate equally good move candidates, then choosing from them 6 | * randomly. But they are also used to juggle group lists (using the 7 | * fact that coord_t == group_t). */ 8 | 9 | #include "move.h" 10 | #include "random.h" 11 | 12 | #define MQL 512 /* XXX: On larger board this might not be enough. */ 13 | struct move_queue { 14 | unsigned int moves; 15 | coord_t move[MQL]; 16 | /* Each move can have an optional tag or set of tags. 17 | * The usage of these is user-dependent. */ 18 | unsigned char tag[MQL]; 19 | }; 20 | 21 | /* Pick a random move from the queue. */ 22 | static coord_t mq_pick(struct move_queue *q); 23 | 24 | /* Add a move to the queue. */ 25 | static void mq_add(struct move_queue *q, coord_t c, unsigned char tag); 26 | 27 | /* Cat two queues together. */ 28 | static void mq_append(struct move_queue *qd, struct move_queue *qs); 29 | 30 | /* Check if the last move in queue is not a dupe, and remove it 31 | * in that case. */ 32 | static void mq_nodup(struct move_queue *q); 33 | 34 | /* Print queue contents on stderr. */ 35 | static void mq_print(struct move_queue *q, struct board *b, char *label); 36 | 37 | 38 | static inline coord_t 39 | mq_pick(struct move_queue *q) 40 | { 41 | return q->moves ? q->move[fast_random(q->moves)] : pass; 42 | } 43 | 44 | static inline void 45 | mq_add(struct move_queue *q, coord_t c, unsigned char tag) 46 | { 47 | assert(q->moves < MQL); 48 | q->tag[q->moves] = tag; 49 | q->move[q->moves++] = c; 50 | } 51 | 52 | static inline void 53 | mq_append(struct move_queue *qd, struct move_queue *qs) 54 | { 55 | assert(qd->moves + qs->moves < MQL); 56 | memcpy(&qd->tag[qd->moves], qs->tag, qs->moves * sizeof(*qs->tag)); 57 | memcpy(&qd->move[qd->moves], qs->move, qs->moves * sizeof(*qs->move)); 58 | qd->moves += qs->moves; 59 | } 60 | 61 | static inline void 62 | mq_nodup(struct move_queue *q) 63 | { 64 | for (unsigned int i = 1; i < 4; i++) { 65 | if (q->moves <= i) 66 | return; 67 | if (q->move[q->moves - 1 - i] == q->move[q->moves - 1]) { 68 | q->tag[q->moves - 1 - i] |= q->tag[q->moves - 1]; 69 | q->moves--; 70 | return; 71 | } 72 | } 73 | } 74 | 75 | static inline void 76 | mq_print(struct move_queue *q, struct board *b, char *label) 77 | { 78 | fprintf(stderr, "%s candidate moves: ", label); 79 | for (unsigned int i = 0; i < q->moves; i++) { 80 | fprintf(stderr, "%s ", coord2sstr(q->move[i], b)); 81 | } 82 | fprintf(stderr, "\n"); 83 | } 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /jni/pachi/network.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_NETWORK_H 2 | #define PACHI_NETWORK_H 3 | 4 | #ifdef _WIN32 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | int port_listen(char *port, int max_connections); 11 | int open_server_connection(int socket, struct in_addr *client); 12 | void open_log_port(char *port); 13 | void open_gtp_connection(int *socket, char *port); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /jni/pachi/ownermap.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_OWNERMAP_H 2 | #define PACHI_OWNERMAP_H 3 | 4 | /* Map of board intersection owners, and devices to derive group status 5 | * information from the map. */ 6 | 7 | #include // sig_atomic_t 8 | 9 | struct board_ownermap { 10 | /* Map of final owners of all intersections on the board. */ 11 | /* This may be shared between multiple threads! */ 12 | /* XXX: We assume sig_atomic_t is thread-atomic. This may not 13 | * be true in pathological cases. */ 14 | sig_atomic_t playouts; 15 | /* At the final board position, for each coordinate increase the 16 | * counter of appropriate color. */ 17 | sig_atomic_t (*map)[S_MAX]; // [board_size2(b)] 18 | }; 19 | 20 | void board_ownermap_fill(struct board_ownermap *ownermap, struct board *b); 21 | void board_ownermap_merge(int bsize2, struct board_ownermap *dst, struct board_ownermap *src); 22 | 23 | 24 | /* Estimate coord ownership based on ownermap stats. */ 25 | enum point_judgement { 26 | PJ_DAME = S_NONE, 27 | PJ_BLACK = S_BLACK, 28 | PJ_WHITE = S_WHITE, 29 | PJ_UNKNOWN = 3, 30 | }; 31 | enum point_judgement board_ownermap_judge_point(struct board_ownermap *ownermap, coord_t c, floating_t thres); 32 | 33 | 34 | /* Estimate status of stones on board based on ownermap stats. */ 35 | struct group_judgement { 36 | floating_t thres; 37 | enum gj_state { 38 | GS_NONE, 39 | GS_DEAD, 40 | GS_ALIVE, 41 | GS_UNKNOWN, 42 | } *gs; // [bsize2] 43 | }; 44 | void board_ownermap_judge_groups(struct board *b, struct board_ownermap *ownermap, struct group_judgement *judge); 45 | 46 | /* Add groups of given status to mq. */ 47 | struct move_queue; 48 | void groups_of_status(struct board *b, struct group_judgement *judge, enum gj_state s, struct move_queue *mq); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /jni/pachi/patternplay/Makefile: -------------------------------------------------------------------------------- 1 | INCLUDES=-I.. 2 | OBJS=patternplay.o 3 | 4 | all: patternplay.a 5 | patternplay.a: $(OBJS) 6 | 7 | clean: 8 | rm -f *.o *.a 9 | clean-profiled: 10 | rm -f *.gcda *.gcno 11 | 12 | -include ../Makefile.lib 13 | -------------------------------------------------------------------------------- /jni/pachi/patternplay/patternplay.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_PATTERNPLAY_PATTERNPLAY_H 2 | #define PACHI_PATTERNPLAY_PATTERNPLAY_H 3 | 4 | #include "engine.h" 5 | 6 | struct engine *engine_patternplay_init(char *arg, struct board *b); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /jni/pachi/patternprob.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_PATTERNPROB_H 2 | #define PACHI_PATTERNPROB_H 3 | 4 | /* Pattern probability table. */ 5 | 6 | #include 7 | 8 | #include "board.h" 9 | #include "move.h" 10 | #include "pattern.h" 11 | 12 | 13 | /* The pattern probability table considers each pattern as a whole 14 | * (not dividing it to individual features) and stores probability 15 | * of the pattern being played. */ 16 | 17 | /* The table primary key is the pattern spatial (most distinctive 18 | * feature); within a single primary key chain, the entries are 19 | * unsorted (for now). */ 20 | 21 | struct pattern_prob { 22 | struct pattern p; 23 | floating_t prob; 24 | struct pattern_prob *next; 25 | }; 26 | 27 | struct pattern_pdict { 28 | struct pattern_config *pc; 29 | 30 | struct pattern_prob **table; /* [pc->spat_dict->nspatials + 1] */ 31 | }; 32 | 33 | /* Initialize the pdict data structure from a given file (pass NULL 34 | * to use default filename). Returns NULL if the file with patterns 35 | * has been found. */ 36 | struct pattern_pdict *pattern_pdict_init(char *filename, struct pattern_config *pc); 37 | 38 | /* Return probability associated with given pattern. Returns NaN if 39 | * the pattern cannot be found. */ 40 | static floating_t pattern_prob(struct pattern_pdict *dict, struct pattern *p); 41 | 42 | /* Evaluate patterns for all available moves. Stores found patterns 43 | * to pats[b->flen] and NON-normalized probability of each pattern 44 | * (or NaN in case of no match) to probs[b->flen]. Returns the sum 45 | * of all probabilities that can be used for normalization. */ 46 | floating_t pattern_rate_moves(struct pattern_setup *pat, 47 | struct board *b, enum stone color, 48 | struct pattern *pats, floating_t *probs); 49 | 50 | /* Utility function - extract spatial id from a pattern. If the pattern 51 | * has no spatial feature, it is represented by the highest spatial id 52 | * plus one. */ 53 | static uint32_t pattern2spatial(struct pattern_pdict *dict, struct pattern *p); 54 | 55 | 56 | static inline floating_t 57 | pattern_prob(struct pattern_pdict *dict, struct pattern *p) 58 | { 59 | uint32_t spi = pattern2spatial(dict, p); 60 | for (struct pattern_prob *pb = dict->table[spi]; pb; pb = pb->next) 61 | if (pattern_eq(p, &pb->p)) 62 | return pb->prob; 63 | return NAN; // XXX: We assume quiet NAN existence 64 | } 65 | 66 | static inline uint32_t 67 | pattern2spatial(struct pattern_pdict *dict, struct pattern *p) 68 | { 69 | for (int i = 0; i < p->n; i++) 70 | if (p->f[i].id == FEAT_SPATIAL) 71 | return p->f[i].payload; 72 | return dict->pc->spat_dict->nspatials; 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /jni/pachi/patternscan/Makefile: -------------------------------------------------------------------------------- 1 | INCLUDES=-I.. 2 | OBJS=patternscan.o 3 | 4 | all: patternscan.a 5 | patternscan.a: $(OBJS) 6 | 7 | clean: 8 | rm -f *.o *.a 9 | clean-profiled: 10 | rm -f *.gcda *.gcno 11 | 12 | -include ../Makefile.lib 13 | -------------------------------------------------------------------------------- /jni/pachi/patternscan/patternscan.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_PATTERNSCAN_PATTERNSCAN_H 2 | #define PACHI_PATTERNSCAN_PATTERNSCAN_H 3 | 4 | #include "engine.h" 5 | 6 | struct engine *engine_patternscan_init(char *arg, struct board *b); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /jni/pachi/playout/Makefile: -------------------------------------------------------------------------------- 1 | INCLUDES=-I.. 2 | OBJS=moggy.o light.o 3 | 4 | all: playout.a 5 | playout.a: $(OBJS) 6 | 7 | clean: 8 | rm -f *.o *.a 9 | clean-profiled: 10 | rm -f *.gcda *.gcno 11 | 12 | -include ../Makefile.lib 13 | -------------------------------------------------------------------------------- /jni/pachi/playout/light.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "board.h" 6 | #include "debug.h" 7 | #include "playout.h" 8 | #include "playout/light.h" 9 | #include "random.h" 10 | 11 | 12 | #define PLDEBUGL(n) DEBUGL_(p->debug_level, n) 13 | 14 | 15 | coord_t 16 | playout_light_choose(struct playout_policy *p, struct playout_setup *s, struct board *b, enum stone to_play) 17 | { 18 | return pass; 19 | } 20 | 21 | 22 | struct playout_policy * 23 | playout_light_init(char *arg, struct board *b) 24 | { 25 | struct playout_policy *p = calloc2(1, sizeof(*p)); 26 | p->choose = playout_light_choose; 27 | 28 | if (arg) 29 | fprintf(stderr, "playout-light: This policy does not accept arguments (%s)\n", arg); 30 | 31 | return p; 32 | } 33 | -------------------------------------------------------------------------------- /jni/pachi/playout/light.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_PLAYOUT_LIGHT_H 2 | #define PACHI_PLAYOUT_LIGHT_H 3 | 4 | struct board; 5 | struct playout_policy; 6 | 7 | struct playout_policy *playout_light_init(char *arg, struct board *b); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /jni/pachi/playout/moggy.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_PLAYOUT_MOGGY_H 2 | #define PACHI_PLAYOUT_MOGGY_H 3 | 4 | struct board; 5 | struct playout_policy; 6 | struct joseki_dict; 7 | 8 | struct playout_policy *playout_moggy_init(char *arg, struct board *b, struct joseki_dict *jdict); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /jni/pachi/probdist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | //#define DEBUG 7 | #include "debug.h" 8 | #include "move.h" 9 | #include "probdist.h" 10 | #include "random.h" 11 | #include "board.h" 12 | 13 | coord_t 14 | probdist_pick(struct probdist *restrict pd, coord_t *restrict ignore) 15 | { 16 | fixp_t total = probdist_total(pd); 17 | fixp_t stab = fast_irandom(total); 18 | if (DEBUGL(6)) 19 | fprintf(stderr, "stab %f / %f\n", fixp_to_double(stab), fixp_to_double(total)); 20 | 21 | int r = 1; 22 | coord_t c = board_size(pd->b) + 1; 23 | while (stab > pd->rowtotals[r]) { 24 | if (DEBUGL(6)) 25 | fprintf(stderr, "[%s] skipping row %f (%f)\n", coord2sstr(c, pd->b), fixp_to_double(pd->rowtotals[r]), fixp_to_double(stab)); 26 | 27 | stab -= pd->rowtotals[r]; 28 | r++; assert(r < board_size(pd->b)); 29 | 30 | c += board_size(pd->b); 31 | while (!is_pass(*ignore) && *ignore <= c) 32 | ignore++; 33 | } 34 | 35 | for (; c < board_size2(pd->b); c++) { 36 | if (DEBUGL(6)) 37 | fprintf(stderr, "[%s] %f (%f)\n", coord2sstr(c, pd->b), fixp_to_double(pd->items[c]), fixp_to_double(stab)); 38 | 39 | assert(is_pass(*ignore) || c <= *ignore); 40 | if (c == *ignore) { 41 | if (DEBUGL(6)) 42 | fprintf(stderr, "\tignored\n"); 43 | ignore++; 44 | continue; 45 | } 46 | 47 | if (stab <= pd->items[c]) 48 | return c; 49 | stab -= pd->items[c]; 50 | } 51 | 52 | fprintf(stderr, "overstab %f (total %f)\n", fixp_to_double(stab), fixp_to_double(total)); 53 | assert(0); 54 | return -1; 55 | } 56 | -------------------------------------------------------------------------------- /jni/pachi/probdist.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_PROBDIST_H 2 | #define PACHI_PROBDIST_H 3 | 4 | /* Tools for picking an item according to a probability distribution. */ 5 | 6 | /* The probability distribution structure is designed to be once 7 | * initialized, then random items assigned a value repeatedly and 8 | * random items picked repeatedly as well. */ 9 | 10 | #include "fixp.h" 11 | #include "move.h" 12 | #include "util.h" 13 | 14 | struct board; 15 | 16 | /* The interface looks a bit funny-wrapped since we used to switch 17 | * between different probdist representations. */ 18 | 19 | struct probdist { 20 | struct board *b; 21 | fixp_t *items; // [bsize2], [i] = P(pick==i) 22 | fixp_t *rowtotals; // [bsize], [i] = sum of items in row i 23 | fixp_t total; // sum of all items 24 | }; 25 | 26 | 27 | /* Declare pd_ corresponding to board b_ in the local scope. */ 28 | #define probdist_alloca(pd_, b_) \ 29 | fixp_t pd_ ## __pdi[board_size2(b_)] __attribute__((aligned(32))); memset(pd_ ## __pdi, 0, sizeof(pd_ ## __pdi)); \ 30 | fixp_t pd_ ## __pdr[board_size(b_)] __attribute__((aligned(32))); memset(pd_ ## __pdr, 0, sizeof(pd_ ## __pdr)); \ 31 | struct probdist pd_ = { .b = b_, .items = pd_ ## __pdi, .rowtotals = pd_ ## __pdr, .total = 0 }; 32 | 33 | /* Get the value of given item. */ 34 | #define probdist_one(pd, c) ((pd)->items[c]) 35 | 36 | /* Get the cummulative probability value (normalizing constant). */ 37 | #define probdist_total(pd) ((pd)->total) 38 | 39 | /* Set the value of given item. */ 40 | static void probdist_set(struct probdist *pd, coord_t c, fixp_t val); 41 | 42 | /* Remove the item from the totals; this is used when you then 43 | * pass it in the ignore list to probdist_pick(). Of course you 44 | * must restore the totals afterwards. */ 45 | static void probdist_mute(struct probdist *pd, coord_t c); 46 | 47 | /* Pick a random item. ignore is a pass-terminated sorted array of items 48 | * that are not to be considered (and whose values are not in @total). */ 49 | coord_t probdist_pick(struct probdist *pd, coord_t *ignore); 50 | 51 | 52 | /* Now, we do something horrible - include board.h for the inline helpers. 53 | * Yay for us. */ 54 | #include "board.h" 55 | 56 | 57 | static inline void 58 | probdist_set(struct probdist *pd, coord_t c, fixp_t val) 59 | { 60 | /* We disable the assertions here since this is quite time-critical 61 | * part of code, and also the compiler is reluctant to inline the 62 | * functions otherwise. */ 63 | #if 0 64 | assert(c >= 0 && c < board_size2(pd->b)); 65 | assert(val >= 0); 66 | #endif 67 | pd->total += val - pd->items[c]; 68 | pd->rowtotals[coord_y(c, pd->b)] += val - pd->items[c]; 69 | pd->items[c] = val; 70 | } 71 | 72 | static inline void 73 | probdist_mute(struct probdist *pd, coord_t c) 74 | { 75 | pd->total -= pd->items[c]; 76 | pd->rowtotals[coord_y(c, pd->b)] -= pd->items[c]; 77 | } 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /jni/pachi/random.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "random.h" 4 | 5 | 6 | /* Simple Park-Miller */ 7 | 8 | #ifndef NO_THREAD_LOCAL 9 | 10 | static __thread unsigned long pmseed = 29264; 11 | 12 | void 13 | fast_srandom(unsigned long seed_) 14 | { 15 | pmseed = seed_; 16 | } 17 | 18 | unsigned long 19 | fast_getseed(void) 20 | { 21 | return pmseed; 22 | } 23 | 24 | uint16_t 25 | fast_random(unsigned int max) 26 | { 27 | unsigned long hi, lo; 28 | lo = 16807 * (pmseed & 0xffff); 29 | hi = 16807 * (pmseed >> 16); 30 | lo += (hi & 0x7fff) << 16; 31 | lo += hi >> 15; 32 | pmseed = (lo & 0x7fffffff) + (lo >> 31); 33 | return ((pmseed & 0xffff) * max) >> 16; 34 | } 35 | 36 | float 37 | fast_frandom(void) 38 | { 39 | /* Construct (1,2) IEEE floating_t from our random integer */ 40 | /* http://rgba.org/articles/sfrand/sfrand.htm */ 41 | union { unsigned long ul; floating_t f; } p; 42 | p.ul = (((pmseed *= 16807) & 0x007fffff) - 1) | 0x3f800000; 43 | return p.f - 1.0f; 44 | } 45 | 46 | #else 47 | 48 | /* Thread local storage not supported through __thread, 49 | * use pthread_getspecific() instead. */ 50 | 51 | #include 52 | 53 | static pthread_key_t seed_key; 54 | 55 | static void __attribute__((constructor)) 56 | random_init(void) 57 | { 58 | pthread_key_create(&seed_key, NULL); 59 | fast_srandom(29264UL); 60 | } 61 | 62 | void 63 | fast_srandom(unsigned long seed_) 64 | { 65 | pthread_setspecific(seed_key, (void *)seed_); 66 | } 67 | 68 | unsigned long 69 | fast_getseed(void) 70 | { 71 | return (unsigned long)pthread_getspecific(seed_key); 72 | } 73 | 74 | uint16_t 75 | fast_random(unsigned int max) 76 | { 77 | unsigned long pmseed = (unsigned long)pthread_getspecific(seed_key); 78 | unsigned long hi, lo; 79 | lo = 16807 * (pmseed & 0xffff); 80 | hi = 16807 * (pmseed >> 16); 81 | lo += (hi & 0x7fff) << 16; 82 | lo += hi >> 15; 83 | pmseed = (lo & 0x7fffffff) + (lo >> 31); 84 | pthread_setspecific(seed_key, (void *)pmseed); 85 | return ((pmseed & 0xffff) * max) >> 16; 86 | } 87 | 88 | float 89 | fast_frandom(void) 90 | { 91 | /* Construct (1,2) IEEE floating_t from our random integer */ 92 | /* http://rgba.org/articles/sfrand/sfrand.htm */ 93 | unsigned long pmseed = (unsigned long)pthread_getspecific(seed_key); 94 | pmseed *= 16807; 95 | union { unsigned long ul; floating_t f; } p; 96 | p.ul = ((pmseed & 0x007fffff) - 1) | 0x3f800000; 97 | pthread_setspecific(seed_key, (void *)pmseed); 98 | return p.f - 1.0f; 99 | } 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /jni/pachi/random.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_RANDOM_H 2 | #define PACHI_RANDOM_H 3 | 4 | #include 5 | 6 | #include "util.h" 7 | 8 | void fast_srandom(unsigned long seed); 9 | unsigned long fast_getseed(void); 10 | 11 | /* Note that only 16bit numbers can be returned. */ 12 | uint16_t fast_random(unsigned int max); 13 | /* Use this one if you want larger numbers. */ 14 | static uint32_t fast_irandom(unsigned int max); 15 | 16 | /* Get random number in [0..1] range. */ 17 | float fast_frandom(); 18 | 19 | 20 | static inline uint32_t 21 | fast_irandom(unsigned int max) 22 | { 23 | if (max <= 65536) 24 | return fast_random(max); 25 | int himax = (max - 1) / 65536; 26 | uint16_t hi = fast_random(himax + 1); 27 | return ((uint32_t)hi << 16) | fast_random(hi < himax ? 65536 : max % 65536); 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /jni/pachi/random/Makefile: -------------------------------------------------------------------------------- 1 | INCLUDES=-I.. 2 | OBJS=random.o 3 | 4 | all: random.a 5 | random.a: $(OBJS) 6 | 7 | clean: 8 | rm -f *.o *.a 9 | clean-profiled: 10 | rm -f *.gcda *.gcno 11 | 12 | -include ../Makefile.lib 13 | -------------------------------------------------------------------------------- /jni/pachi/random/random.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "board.h" 5 | #include "engine.h" 6 | #include "move.h" 7 | #include "random/random.h" 8 | 9 | static coord_t * 10 | random_genmove(struct engine *e, struct board *b, struct time_info *ti, enum stone color, bool pass_all_alive) 11 | { 12 | /* Play a random coordinate. However, we must also guard 13 | * against suicide moves; repeat playing while it's a suicide 14 | * unless we keep suiciding; in that case, we probably don't 15 | * have any other moves available and we pass. */ 16 | coord_t coord; 17 | int i = 0; bool suicide = false; 18 | 19 | do { 20 | /* board_play_random() actually plays the move too; 21 | * this is desirable for MC simulations but not within 22 | * the genmove. Make a scratch new board for it. */ 23 | struct board b2; 24 | board_copy(&b2, b); 25 | 26 | board_play_random(&b2, color, &coord, NULL, NULL); 27 | 28 | suicide = (coord != pass && !group_at(&b2, coord)); 29 | board_done_noalloc(&b2); 30 | } while (suicide && i++ < 100); 31 | 32 | return coord_copy(suicide ? pass : coord); 33 | } 34 | 35 | struct engine * 36 | engine_random_init(char *arg, struct board *b) 37 | { 38 | struct engine *e = calloc2(1, sizeof(struct engine)); 39 | e->name = "RandomMove"; 40 | e->comment = "I just make random moves. I won't pass as long as there is a place on the board where I can play. When we both pass, I will consider all the stones on the board alive."; 41 | e->genmove = random_genmove; 42 | 43 | if (arg) 44 | fprintf(stderr, "Random: I support no engine arguments\n"); 45 | 46 | return e; 47 | } 48 | -------------------------------------------------------------------------------- /jni/pachi/random/random.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_RANDOM_RANDOM_H 2 | #define PACHI_RANDOM_RANDOM_H 3 | 4 | #include "engine.h" 5 | 6 | struct engine *engine_random_init(char *arg, struct board *b); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /jni/pachi/replay/Makefile: -------------------------------------------------------------------------------- 1 | INCLUDES=-I.. 2 | OBJS=replay.o 3 | 4 | all: replay.a 5 | replay.a: $(OBJS) 6 | 7 | clean: 8 | rm -f *.o *.a 9 | clean-profiled: 10 | rm -f *.gcda *.gcno 11 | 12 | -include ../Makefile.lib 13 | -------------------------------------------------------------------------------- /jni/pachi/replay/replay.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_REPLAY_REPLAY_H 2 | #define PACHI_REPLAY_REPLAY_H 3 | 4 | #include "engine.h" 5 | 6 | struct engine *engine_replay_init(char *arg, struct board *b); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /jni/pachi/stone.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "stone.h" 6 | 7 | char * 8 | stone2str(enum stone s) 9 | { 10 | switch (s) { 11 | case S_BLACK: return "black"; 12 | case S_WHITE: return "white"; 13 | default: return "none"; 14 | } 15 | } 16 | 17 | enum stone 18 | str2stone(char *str) 19 | { 20 | switch (tolower(*str)) { 21 | case 'b': return S_BLACK; 22 | case 'w': return S_WHITE; 23 | default: return S_NONE; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /jni/pachi/stone.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_STONE_H 2 | #define PACHI_STONE_H 3 | 4 | enum stone { 5 | S_NONE, 6 | S_BLACK, 7 | S_WHITE, 8 | S_OFFBOARD, 9 | S_MAX, 10 | }; 11 | 12 | static char stone2char(enum stone s); 13 | static enum stone char2stone(char s); 14 | char *stone2str(enum stone s); /* static string */ 15 | enum stone str2stone(char *str); 16 | 17 | static enum stone stone_other(enum stone s); 18 | 19 | 20 | static inline char 21 | stone2char(enum stone s) 22 | { 23 | return ".XO#"[s]; 24 | } 25 | 26 | static inline enum stone 27 | char2stone(char s) 28 | { 29 | switch (s) { 30 | case '.': return S_NONE; 31 | case 'X': return S_BLACK; 32 | case 'O': return S_WHITE; 33 | case '#': return S_OFFBOARD; 34 | } 35 | return S_NONE; // XXX 36 | } 37 | 38 | /* Curiously, gcc is reluctant to inline this; I have cofirmed 39 | * there is performance benefit. */ 40 | static inline enum stone __attribute__((always_inline)) 41 | stone_other(enum stone s) 42 | { 43 | static const enum stone o[S_MAX] = { S_NONE, S_WHITE, S_BLACK, S_OFFBOARD }; 44 | return o[s]; 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /jni/pachi/t-play/autotest/TODO: -------------------------------------------------------------------------------- 1 | * Support for handicap settings 2 | 3 | * Support for automatic checking against loss-by-points 4 | (desirable for UCT players) 5 | 6 | * Caching unchanged results - faster ./autotest-show 7 | 8 | * Nicer support for disconnected usage 9 | 10 | * Support for multi-core systems and multi-threaded players 11 | 12 | * Support for using different(ly optimized) binaries based 13 | on host architecture / processor type 14 | -------------------------------------------------------------------------------- /jni/pachi/t-play/autotest/autotest-client: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This is autotest Go-testing framework client. It runs on client 3 | # machines and spawns autotest-worker, which picks a random pairing 4 | # among the ones defined in the rc file, and plays a single game. 5 | 6 | clientid="$1"; shift 7 | if [ -z "$clientid" ]; then 8 | echo "Usage: $0 " >&2 9 | echo "At any time, only single client with the same client may run!" >&2 10 | echo "You can use e.g. clientid \`hostname\`-1, increment 1 for" >&2 11 | echo "further threads started on the host." >&2 12 | exit 1 13 | fi 14 | . ./autotest-lib 15 | 16 | mkdir -p "c/$clientid" 17 | log "started client ($clientid)" 18 | 19 | while true; do 20 | mkdir -p "c/$clientid" 21 | date +%s >"c/$clientid/beacon" 22 | if ! ./autotest-worker "$clientid"; then 23 | echo "*** WORKER FAILED ***" 24 | log "worker failed with error code $?" 25 | sleep 1 26 | fi 27 | done 28 | -------------------------------------------------------------------------------- /jni/pachi/t-play/autotest/autotest-clients: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This is autotest client lister. 3 | 4 | . ./autotest-lib 5 | 6 | echo -e "LAST ACTIVITY\t\t\tWFAIL#\tNAME" 7 | for c in c/*; do 8 | client="${c#c/}" 9 | beacon="$(date --rfc-3339=seconds -d "1970-01-01 $(cat "$c/beacon") seconds")" 10 | fails="$(grep -c fail "$c/log" || :)" 11 | echo -e "$beacon\t$fails\t$client" 12 | done 13 | -------------------------------------------------------------------------------- /jni/pachi/t-play/autotest/autotest-gather: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This is autotest gathering tool, collecting game result info from 3 | # all clients and putting it in single place (which is completely 4 | # wiped otherwise). 5 | 6 | . ./autotest-lib 7 | 8 | mkdir -p "r/" 9 | rm -f r/* 10 | 11 | # First, gather pairing data: 12 | 13 | for dir in c/*/*/; do 14 | pairing="${dir%/}"; pairing="${pairing#c/*/}" 15 | datfile="r/$pairing.dat" 16 | 17 | if [ ! -s "$datfile" ]; then 18 | # Common datfile header, required for twogtp -analyze 19 | { 20 | echo "#" 21 | echo -e "#GAME\tRES_B\tRES_W\tRES_R\tALT\tDUP\tLEN\tTIME_B\tTIME_W\tCPU_B\tCPU_W\tERR\tERR_MSG" 22 | } >"$datfile" 23 | num=0 24 | else 25 | lastgame="$(tail -n 1 "$datfile")" 26 | num="$((${lastgame%% *} + 1))" 27 | fi 28 | # We cannot simply concatenate all the datfiles because 29 | # twogtp -analyze is pedantic about the games numbering; 30 | # we need to renumber the games to a single sequence. 31 | while read orignum line; do 32 | echo -e "$num\t$line" 33 | num=$((num+1)) 34 | done <"$dir/game.dat" >>"$datfile" 35 | done 36 | 37 | 38 | # Next, fill per-pairing metadata: 39 | 40 | for datfile in r/*.dat; do 41 | pairing="${datfile%.dat}"; pairing="${pairing#r/}" 42 | 43 | # Look at last change in pairing: 44 | stat -c %Z "$(ls --sort=time c/*/"$pairing"/* | head -n 1)" >"r/$pairing.beacon" 45 | 46 | # Check pairing for errors: 47 | tail -n +3 "$datfile" | cut -f 12 | { grep -c -vF 0 >"r/$pairing.error" || :; } 48 | done 49 | -------------------------------------------------------------------------------- /jni/pachi/t-play/autotest/autotest-lib: -------------------------------------------------------------------------------- 1 | # Library of common shell functions for the autotest framework. 2 | 3 | set -e # errors are fatal 4 | 5 | 6 | # Client helpers. $clientid must be set. 7 | 8 | log() { 9 | echo -e "$(date)\t$*" >>"c/$clientid/log" 10 | } 11 | 12 | 13 | # Generic functions. 14 | 15 | pairid() { 16 | echo "$*" | tr ' ' '-' 17 | } 18 | -------------------------------------------------------------------------------- /jni/pachi/t-play/autotest/autotest-prune: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This is autotest pruning tool, removing info about specified old 3 | # pairings. Note that this removes only pairing results, you need 4 | # to adjust the rc file manually if you haven't removed the pairing 5 | # specifiers from there yet. 6 | 7 | mask="$1" 8 | if [ -z "$mask" ]; then 9 | echo "Usage: $0 MASK" >&2 10 | echo "MASK can be pairing name, or a glob pattern (*, ?)." >&2 11 | echo "Use \`$0 *\` to remove all pairings." >&2 12 | exit 1 13 | fi 14 | . ./autotest-lib 15 | 16 | echo "Removing $(ls r/$mask.dat | wc -l) result pairs..." 17 | rm -f r/$mask.dat r/$mask.summary.dat r/$mask.html r/$mask.beacon r/$mask.error 18 | rm -rf c/*/$mask 19 | -------------------------------------------------------------------------------- /jni/pachi/t-play/autotest/autotest-show: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This is autotest display tool, showing gathered information in 3 | # a hopefully meaningful way. 4 | 5 | mask="$1" 6 | [ -n "$mask" ] || mask="*" 7 | . ./autotest-lib 8 | 9 | if [ ! -d "r" ]; then 10 | echo "Did you run autotest-gather?" >&2 11 | exit 1 12 | fi 13 | 14 | # Load rc quickly: 15 | player() { :; } 16 | pknown=" " 17 | pairing() { pknown="$pknown$(pairid "$@") "; } 18 | . ./rc 19 | 20 | color_stale="\033[33m" 21 | color_bad="\033[31m" 22 | color_fresh="\033[1m" 23 | color_stop="\033[0m" 24 | 25 | pairing_status() { 26 | # See README for explanation of flags. 27 | error=0; 28 | if [ -s "r/$pairing.error" ] && [ "$(cat "r/$pairing.error")" -gt 0 ]; then 29 | error=1; 30 | fi 31 | known=1; [ "${pknown#* $pairing *}" != "$pknown" ] || known=0 32 | active=1; ([ -s "r/$pairing.beacon" ] && [ "$(cat "r/$pairing.beacon")" -ge "$(($(date +%s) - 60*60*2))" ]) || active=0 33 | case $error$known$active in 34 | 001) status="${color_stale}?";; 35 | 000) status="${color_stale}/";; 36 | 011) status="${color_fresh}.";; 37 | 010) status="${color_fresh}${color_bad}!";; 38 | 1*0) status="${color_bad}x";; 39 | 1*1) status="${color_fresh}${color_bad}X";; 40 | esac 41 | } 42 | 43 | rm -f r/*.summary.dat r/*.html 44 | 45 | echo -e "S GAMES\tWINRATE\tS.D.\tPAIRING" 46 | for pairing in $((echo "$pknown" | tr ' ' '\n'; ls r/*.dat | sed 's#^r/##; s#\.dat$##') | sort | uniq); do 47 | [ ! -s "r/$pairing.dat" ] || $twogtp_path -analyze "r/$pairing.dat" 48 | pairing_status "$pairing" # sets status 49 | if [ -s "r/$pairing.summary.dat" ]; then 50 | echo -e "$status $(cat "r/${pairing}".summary.dat | cut -f 1,7,8 | tail -n +2)\t$pairing$color_stop" 51 | else 52 | echo -e "$status 0\t-\t-\t$pairing$color_stop" 53 | fi 54 | done 55 | -------------------------------------------------------------------------------- /jni/pachi/t-play/autotest/rc: -------------------------------------------------------------------------------- 1 | # This is rc file for the autotest framework. It is interpreted as a shell 2 | # snippet, so sh/bash evaluation rules apply. 3 | 4 | # Here, we define some general execution environment configuration for 5 | # autotest, the players that will get paired, and then actual pairings 6 | # to perform. autotest clients will repeatedly pick a random pairing 7 | # from the defined ones, play a game and record the result. 8 | 9 | ### General parameters: 10 | 11 | # twogtp path - we need the gogui twogtp variant (the one that takes -black, 12 | # not --black as parameter) 13 | twogtp_path="/nfs/drahokam/pasky/gogui-1.1.10/bin/gogui-twogtp" 14 | # If you want handicap support, you will need a custom patch from: 15 | # https://sourceforge.net/tracker/?func=detail&atid=489966&aid=2878719&group_id=59117 16 | 17 | 18 | ### Players: 19 | # The player specification is later eval'd during the payring. You can use 20 | # $1, $2, ... placeholders within the specification to substitute various 21 | # parameters at the pairing time. The number parameter after player command 22 | # specification specifies how many parameters the specification takes. 23 | 24 | # Warning! If you change player definition, you WILL NOT be able to determine 25 | # what definition your historical results used. Once you define a player of 26 | # some id, it's bad idea to tweak the definition in any way. 27 | 28 | # This is the reference player we use for our tests. 29 | player gnugo10 'gnugo --mode gtp --chinese-rules --capture-all-dead --level 10' 0 30 | 31 | # This is generic Pachi player that is being tested, we substitute particular 32 | # revision and specific parameters in the pairings. 33 | # ${2:+,$2} means that if second parameter is passed, it will be inserted here, 34 | # comma-prepended, otherwise nothing will be inserted. 35 | player zamafmoggy5k './pachi-$1 games=5000,pass_all_alive,policy=ucb1amaf,playout=moggy${2:+,$2}' 2 36 | 37 | 38 | ### Pairings: 39 | # The pairing call looks somewhat elaborate: 40 | # 41 | # pairing BOARDSIZE KOMI BLACK PLAYER1 PLAYER1ARGS PLAYER2 PLAYER2ARGS 42 | # BOARDSIZE: 9, 19, or whatever flavor you fancy... 43 | # KOMI: 7.5, 0.5, ... OR h2, h6, ... (handicap amount, komi is forced to 0.5) 44 | # BLACK: 'a' - black is chosen randomly, useful only if komi is 7.5 45 | # '1' - black is PLAYER1, '2' - black is PLAYER2 46 | # PLAYER: Name of the player as defined above. 47 | # PLAYERARGS: Parameters for the player, substituted for $1, $2, ... 48 | # Parameters must not contain whitespace. 49 | # 50 | # Win rates are always stored from PLAYER2 perspective, no matter 51 | # what the player colors are - we assume that PLAYER1 is your reference 52 | # player while PLAYER2 varies based on the particular configuration you 53 | # want to test. 54 | 55 | # You will be editing this all the time. :) 56 | 57 | pairing 9 0.5 1 gnugo10 zamafmoggy5k 77d2d 58 | pairing 9 0.5 1 gnugo10 zamafmoggy5k 77d2d amaf_prior=0 59 | -------------------------------------------------------------------------------- /jni/pachi/t-play/resum: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | rm *summ* 3 | brm="$1" 4 | [ -n "$brm" ] || brm="*dat" 5 | for i in $(ls $brm); do 6 | printf "%-40s\t" "${i%.dat}.summary.dat"; 7 | ../../gogui-1.1.10/bin/gogui-twogtp -force -analyze $i; 8 | cat ${i%.dat}.summary.dat | cut -f 1,7,8 | tail -n +2 9 | done 10 | -------------------------------------------------------------------------------- /jni/pachi/t-play/test_in_context.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # $1: path to test results 4 | # $2: board size 5 | 6 | (cd "$1" && ls f$2-*summ*dat) | sed 's/^f'$2'-//; s/[-.].*$//;' | xargs git log --pretty=oneline --no-walk | while read c s; do 7 | echo 8 | echo ================================================ 9 | git log -1 --pretty=medium $c 10 | for t in $(cd "$1" && ls f$2-${c:0:5}*summ*); do 11 | echo 12 | echo $t 13 | cat "$1/$t" | cut -f 1,2,7,8,12,13 14 | done 15 | done 16 | -------------------------------------------------------------------------------- /jni/pachi/t-regress/README: -------------------------------------------------------------------------------- 1 | This is Pachi's regression suite. It contains SGF game records that can 2 | be automatically probed with current Pachi version for particular 3 | behavior (usually observed in older Pachi versions). We do not anticipate 4 | that Pachi would pass all of the tests - when it will, it will be probably 5 | pro strength. ;-) The goal is simply to steadily reduce these and verify 6 | that modifications do not reintroduce bad behavior. 7 | 8 | The game SGF records are in the games/ subdirectory, and also cross-linked 9 | in by-*/ subdirectories based on categories. Each SGF record must contain 10 | a GC[] tag ("game comment") describing the test-case in a manner that is 11 | both human-readable and machine-readable. The description lists specific 12 | moves and how they should be tested, one move per line, using this syntax: 13 | 14 | :[,:,...] 15 | 16 | movenumber: Number of the tested move 17 | movepos: A move coordinate (just for consistency) 18 | classification: Comma-separated list of move classifications, 19 | no whitespaces 20 | comment: Ignored by the testsuite. 21 | 22 | These classifications are available for now: 23 | 24 | bad This move should not be chosen as the next move. 25 | bad! This move is so useless that it should not be in the top 26 | considered moves. (This is a bit feeble class.) 27 | must This move is essential and must be made immediately. 28 | alive This group should be considered alive. 29 | dead This group should be considered dead. 30 | 31 | Classifications may be prefixed by various letters: 32 | 33 | + An issue that is already supposed to be fixed. 34 | / An intermittent issue that happens only in case of some 35 | (mis)fortune in the search. 36 | 37 | Classifications may be postfixed by category name in {curly brackets}. 38 | 39 | Example: 40 | 41 | 40 C3:bad non-working invasion 42 | 41 B2:bad{tsumego},+A1:bad{tsumego} makes C3 alive 43 | -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-falseeye/2011-06-05-Zen19-pachi2.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-06-05-Zen19-pachi2.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-falseeye/2011-06-05-tazaki-pachi30s.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-06-05-tazaki-pachi30s.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-falseeye/2011-06-09-botkiller2-pachi30s.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-06-09-botkiller2-pachi30s.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-falseeye/2011-06-10-pachi30s-samba-2.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-06-10-pachi30s-samba-2.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-falseeye/2011-06-18-dorabon-pachi2-4.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-06-18-dorabon-pachi2-4.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-falseeye/2011-07-28-pachi2-Novicer.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-07-28-pachi2-Novicer.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-falseeye/2011-08-12-xiaosugi-pachi2.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-08-12-xiaosugi-pachi2.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-ko/2011-06-09-jinen-pachi30s-2.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-06-09-jinen-pachi30s-2.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-ladder/2011-01-11-llopl-pachi2.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-01-11-llopl-pachi2.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-ladder/2011-06-06-tyzef-pachi30s.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-06-06-tyzef-pachi30s.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-ladder/2011-06-13-pachi30s-Jep.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-06-13-pachi30s-Jep.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-ladder/2011-07-28-pachi2-pkunzip-2.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-07-28-pachi2-pkunzip-2.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-ladder/2011-08-08-Dallas-pachi2-2.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-08-08-Dallas-pachi2-2.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-ladder/2011-08-09-pachi2-BlueSpark.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-08-09-pachi2-BlueSpark.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-ladder/2011-08-09-somrak-pachi2-2.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-08-09-somrak-pachi2-2.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-ladder/2011-08-24-StoneGrid-pachi2.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-08-24-StoneGrid-pachi2.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-ladder/2011-09-04-pachi2-stv.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-09-04-pachi2-stv.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-ladder/2012-03-16-IMC-pachi2.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2012-03-16-IMC-pachi2.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-semeai/2011-01-15-pachi2-rollingon.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-01-15-pachi2-rollingon.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-semeai/2011-06-05-Zen19-pachi2.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-06-05-Zen19-pachi2.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-semeai/2011-06-05-tazaki-pachi30s.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-06-05-tazaki-pachi30s.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-semeai/2011-06-18-dorabon-pachi2-4.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2011-06-18-dorabon-pachi2-4.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/by-semeai/2012-03-15-pachi2-Leech.sgf: -------------------------------------------------------------------------------- 1 | IntxLNK../games/2012-03-15-pachi2-Leech.sgf -------------------------------------------------------------------------------- /jni/pachi/t-regress/games/2011-01-11-llopl-pachi2.sgf: -------------------------------------------------------------------------------- 1 | (;GM[1]FF[4]CA[UTF-8]AP[CGoban:3]ST[2] 2 | RU[Chinese]SZ[19]KM[7.50]TM[1200]OT[3x10 byo-yomi] 3 | PW[llopl]PB[pachi2]DT[2011-01-11]GC[21 +F12:bad!{ladder} terrible ladder bug]PC[The KGS Go Server at http://www.gokgs.com/]C[pachi2 [-\]: GTP Engine for pachi2 (black): Pachi Distributed Engine version 6.99 (Chihaku-devel): I'm playing the distributed engine. When I'm losing, I will resign, if I think I win, I play until you pass. Anyone can send me 'winrate' in private chat to get my assessment of the position. 4 | ]RE[W+Resign] 5 | ;B[pc]BL[1196.953] 6 | ;W[dp]WL[1195.448] 7 | ;B[nf]BL[1187.946] 8 | ;W[dd]WL[1188.944] 9 | ;B[gc]BL[1161.126] 10 | ;W[cg]WL[1178.729] 11 | ;B[df]BL[1135.039] 12 | ;W[cf]WL[1173.539] 13 | ;B[dg]BL[1109.301] 14 | ;W[de]WL[1156.347] 15 | ;B[ch]BL[1101.869] 16 | ;W[dh]WL[1152.82] 17 | ;B[fg]BL[1087.076] 18 | ;W[eh]WL[1139.049] 19 | ;B[ci]BL[1078.444] 20 | ;W[eg]WL[1133.554] 21 | ;B[ef]BL[1070.848] 22 | ;W[ff]WL[1131.04] 23 | ;B[ee]BL[1063.028] 24 | ;W[gg]WL[1117.854] 25 | ;B[fh]BL[1054.881] 26 | ;W[fi]WL[1114.888] 27 | ;B[gh]BL[1046.912] 28 | ;W[hh]WL[1111.394] 29 | ;B[gi]BL[1038.999] 30 | ;W[gj]WL[1108.06] 31 | ;B[hi]BL[1031.402] 32 | ;W[ii]WL[1105.107] 33 | ;B[hj]BL[1023.405] 34 | ;W[hk]WL[1102.009] 35 | ;B[ij]BL[1015.538] 36 | ;W[jj]WL[1099.39] 37 | ;B[ik]BL[1008.158] 38 | ;W[il]WL[1096.626] 39 | ;B[jk]BL[1000.192] 40 | ;W[kk]WL[1094.338] 41 | ;B[jl]BL[992.241] 42 | ;W[jm]WL[1092.01] 43 | ;B[kl]BL[973.574] 44 | ;W[ll]WL[1090.049] 45 | ;B[km]BL[955.539] 46 | ;W[kn]WL[1088.308] 47 | ;B[lm]BL[936.382] 48 | ;W[mm]WL[1085.42] 49 | ;B[ln]BL[918.77] 50 | ;W[lo]WL[1082.54] 51 | ;B[mn]BL[896.152] 52 | ;W[nn]WL[1079.496] 53 | ;B[mo]BL[870.485] 54 | ;W[mp]WL[1076.543]) 55 | -------------------------------------------------------------------------------- /jni/pachi/t-regress/games/2011-06-06-tyzef-pachi30s.sgf: -------------------------------------------------------------------------------- 1 | (;GM[1]FF[4]CA[UTF-8]AP[CGoban:3]ST[2] 2 | RU[Chinese]SZ[19]KM[7.50]TM[1800]OT[5x30 byo-yomi] 3 | PW[tyzef]PB[pachi30s]WR[7k]DT[2011-06-06]GC[17 +D6:bad!{ladder} plays out ladder]PC[The KGS Go Server at http://www.gokgs.com/]C[pachi30s [-\]: GTP Engine for pachi30s (black): Pachi Distributed Engine version 8.99 (Hakugen-devel): I'm playing the distributed engine. When I'm losing, I will resign, if I think I win, I play until you pass. Anyone can send me 'winrate' in private chat to get my assessment of the position. 4 | ]RE[B+Resign] 5 | ;B[qc]BL[1796.606] 6 | ;W[ep]WL[1796.485] 7 | ;B[pq]BL[1718.228] 8 | ;W[po]WL[1763.099] 9 | ;B[mq]BL[1643.515] 10 | ;W[pl]WL[1750.088] 11 | ;B[cp]BL[1562.141] 12 | ;W[do]WL[1521.137] 13 | ;B[cn]BL[1512.02] 14 | ;W[co]WL[1448.438] 15 | ;B[bo]BL[1484.653] 16 | ;W[bp]WL[1403.785] 17 | ;B[bq]BL[1456.25] 18 | ;W[bn]WL[1398.747] 19 | ;B[ap]BL[1427.902] 20 | ;W[cm]WL[1359.821] 21 | ;B[dn]BL[1399.52] 22 | ;W[en]WL[1316.795] 23 | ;B[dm]BL[1371.136] 24 | ;W[dl]WL[1292.431] 25 | ;B[em]BL[1342.671] 26 | ;W[fm]WL[1240.348] 27 | ;B[el]BL[1314.255] 28 | ;W[ek]WL[1237.356] 29 | ;B[fl]BL[1285.74] 30 | ;W[]WL[1237.355] 31 | ;B[fn]BL[1257.253]) 32 | -------------------------------------------------------------------------------- /jni/pachi/t-regress/games/2012-03-16-IMC-pachi2.sgf: -------------------------------------------------------------------------------- 1 | (;GM[1]FF[4]CA[UTF-8]AP[CGoban:3]ST[2] 2 | RU[Chinese]SZ[19]KM[7.50]TM[0]OT[5x15 byo-yomi] 3 | PW[IMC]PB[pachi2]WR[4d]BR[4d]DT[2012-03-16]GC[73 +K13:bad!{ladder} pachi plays a (barely) broken ladder]PC[The KGS Go Server at http://www.gokgs.com/]C[pachi2 [4d\]: GTP Engine for pachi2 (black): Pachi Distributed version 9.99 (Satsugen-devel): If you believe you have won but I am still playing, please help me understand by capturing all dead stones. Anyone can send me 'winrate' in private chat to get my assessment of the position. Have a nice game! 4 | ]RE[W+Resign] 5 | ;B[pp]BL[15]OB[5] 6 | ;W[fi]WL[15]OW[5] 7 | ;B[cp]BL[15]OB[5] 8 | ;W[of]WL[15]OW[5] 9 | ;B[pc]BL[15]OB[5] 10 | ;W[fp]WL[15]OW[5] 11 | ;B[hp]BL[15]OB[5] 12 | ;W[fn]WL[15]OW[5] 13 | ;B[cm]BL[15]OB[5] 14 | ;W[kp]WL[15]OW[5] 15 | ;B[mp]BL[15]OB[5] 16 | ;W[kn]WL[15]OW[5] 17 | ;B[hn]BL[15]OB[5] 18 | ;W[fl]WL[15]OW[5] 19 | ;B[hl]BL[15]OB[5] 20 | ;W[kl]WL[15]OW[5] 21 | ;B[cj]BL[15]OB[5] 22 | ;W[dl]WL[15]OW[5] 23 | ;B[cl]BL[15]OB[5] 24 | ;W[ik]WL[15]OW[5] 25 | ;B[gk]BL[15]OB[5] 26 | ;W[ej]WL[15]OW[5] 27 | ;B[fq]BL[15]OB[5] 28 | ;W[eq]WL[15]OW[5] 29 | ;B[gq]BL[15]OB[5] 30 | ;W[dp]WL[15]OW[5] 31 | ;B[cq]BL[15]OB[5] 32 | ;W[er]WL[15]OW[5] 33 | ;B[do]BL[15]OB[5] 34 | ;W[eo]WL[15]OW[5] 35 | ;B[jq]BL[15]OB[5] 36 | ;W[kq]WL[15]OW[5] 37 | ;B[jp]BL[15]OB[5] 38 | ;W[jo]WL[15]OW[5] 39 | ;B[gi]BL[15]OB[5] 40 | ;W[gj]WL[15]OW[5] 41 | ;B[fk]BL[15]OB[5] 42 | ;W[ek]WL[15]OW[5] 43 | ;B[fj]BL[15]OB[5] 44 | ;W[hj]WL[15]OW[5] 45 | ;B[lo]BL[15]OB[5] 46 | ;W[ko]WL[15]OW[5] 47 | ;B[il]BL[15]OB[5] 48 | ;W[jl]WL[15]OW[5] 49 | ;B[ei]BL[15]OB[5] 50 | ;W[fh]WL[15]OW[5] 51 | ;B[eh]BL[15]OB[5] 52 | ;W[io]WL[15]OW[5] 53 | ;B[ho]BL[15]OB[5] 54 | ;W[gm]WL[15]OW[5] 55 | ;B[hm]BL[15]OB[5] 56 | ;W[dn]WL[15]OW[5] 57 | ;B[co]BL[15]OB[5] 58 | ;W[kr]WL[15]OW[5] 59 | ;B[dm]BL[15]OB[5] 60 | ;W[em]WL[15]OW[5] 61 | ;B[hi]BL[15]OB[5] 62 | ;W[ii]WL[15]OW[5] 63 | ;B[fg]BL[15]OB[5] 64 | ;W[gh]WL[15]OW[5] 65 | ;B[hh]BL[15]OB[5] 66 | ;W[gg]WL[15]OW[5] 67 | ;B[gf]BL[15]OB[5] 68 | ;W[hg]WL[15]OW[5] 69 | ;B[ih]BL[15]OB[5] 70 | ;W[jh]WL[15]OW[5] 71 | ;B[ig]BL[15]OB[5] 72 | ;W[hf]WL[15]OW[5] 73 | ;B[jm]BL[15]OB[5] 74 | ;W[km]WL[15]OW[5] 75 | ;B[jk]BL[15]OB[5] 76 | ;W[if]WL[15]OW[4] 77 | ;B[jg]BL[15]OB[5] 78 | ;W[kg]WL[15]OW[4] 79 | ;B[jf]BL[15]OB[5] 80 | ;W[je]WL[15]OW[4]C[IMC [4d\]: lol 81 | ] 82 | ;B[dk]BL[15]OB[5] 83 | ;W[el]WL[15]OW[4] 84 | ;B[kf]BL[15]OB[5] 85 | ;W[lf]WL[15]OW[4] 86 | ;B[fr]BL[15]OB[5] 87 | ;W[ir]WL[15]OW[4] 88 | ;B[es]BL[15]OB[5] 89 | ;W[dr]WL[15]OW[4] 90 | ;B[cr]BL[15]OB[5] 91 | ;W[ds]WL[15]OW[4] 92 | ;B[jr]BL[15]OB[5] 93 | ;W[hr]WL[15]OW[4] 94 | ;B[ks]BL[15]OB[5] 95 | ;W[ip]WL[15]OW[4] 96 | ;B[hq]BL[15]OB[5] 97 | ;W[iq]WL[15]OW[4] 98 | ;B[dq]BL[15]OB[5] 99 | ;W[ep]WL[15]OW[4]C[IMC [4d\]: lol 100 | ]) 101 | -------------------------------------------------------------------------------- /jni/pachi/t-regress/test-game.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # test-game: Run testcases within a single game 4 | # 5 | # Usage: test-game.sh FILENAME 6 | # 7 | # Examine a game record and run testcases for all moves described 8 | # in the "game comment". 9 | # 10 | # Pass any extra Pachi parameters in PACHIARGS. E.g. 11 | # PACHIARGS='-t =100000 -d 2 threads=2' testgame.sh ... 12 | 13 | sgf="$1" 14 | 15 | sed -ne '/GC\[[0-9][0-9]* .*\]/{s/.*GC\[\([^]]*\)\].*/\1/p; q;}; /GC\[/,/\]/{ s/.*GC\[//; s/\].*//; /^[0-9][0-9]* /p; }' <"$sgf" | 16 | while read moven cases desc; do 17 | echo "Examining move $moven"; sleep 1 18 | tools/sgf2gtp.pl -g -n $((moven-1)) <"$sgf" | ./pachi -t =20000 $PACHIARGS 19 | echo "Testcases: $cases ($desc)" 20 | echo "Confirm and press enter..."; read xx 2 | #include 3 | #include 4 | 5 | #define DEBUG 6 | #include "board.h" 7 | #include "debug.h" 8 | #include "move.h" 9 | #include "tactics/nakade.h" 10 | 11 | 12 | coord_t 13 | nakade_point(struct board *b, coord_t around, enum stone color) 14 | { 15 | /* First, examine the nakade area. For sure, it must be at most 16 | * six points. And it must be within color group(s). */ 17 | #define NAKADE_MAX 6 18 | coord_t area[NAKADE_MAX]; int area_n = 0; 19 | 20 | area[area_n++] = around; 21 | 22 | for (int i = 0; i < area_n; i++) { 23 | foreach_neighbor(b, area[i], { 24 | if (board_at(b, c) == stone_other(color)) 25 | return pass; 26 | if (board_at(b, c) == S_NONE) { 27 | bool dup = false; 28 | for (int j = 0; j < area_n; j++) 29 | if (c == area[j]) { 30 | dup = true; 31 | break; 32 | } 33 | if (dup) continue; 34 | 35 | if (area_n >= NAKADE_MAX) { 36 | /* Too large nakade area. */ 37 | return pass; 38 | } 39 | area[area_n++] = c; 40 | } 41 | }); 42 | } 43 | 44 | /* We also collect adjecency information - how many neighbors 45 | * we have for each area point, and histogram of this. This helps 46 | * us verify the appropriate bulkiness of the shape. */ 47 | int neighbors[area_n]; int ptbynei[9] = {area_n, 0}; 48 | memset(neighbors, 0, sizeof(neighbors)); 49 | for (int i = 0; i < area_n; i++) { 50 | for (int j = i + 1; j < area_n; j++) 51 | if (coord_is_adjecent(area[i], area[j], b)) { 52 | ptbynei[neighbors[i]]--; 53 | neighbors[i]++; 54 | ptbynei[neighbors[i]]++; 55 | ptbynei[neighbors[j]]--; 56 | neighbors[j]++; 57 | ptbynei[neighbors[j]]++; 58 | } 59 | } 60 | 61 | /* For each given neighbor count, arbitrary one coordinate 62 | * featuring that. */ 63 | coord_t coordbynei[9]; 64 | for (int i = 0; i < area_n; i++) 65 | coordbynei[neighbors[i]] = area[i]; 66 | 67 | switch (area_n) { 68 | case 1: return pass; 69 | case 2: return pass; 70 | case 3: assert(ptbynei[2] == 1); 71 | return coordbynei[2]; // middle point 72 | case 4: if (ptbynei[3] != 1) return pass; // long line 73 | return coordbynei[3]; // tetris four 74 | case 5: if (ptbynei[3] == 1 && ptbynei[1] == 1) return coordbynei[3]; // bulky five 75 | if (ptbynei[4] == 1) return coordbynei[4]; // cross five 76 | return pass; // long line 77 | case 6: if (ptbynei[4] == 1 && ptbynei[2] == 3) 78 | return coordbynei[4]; // rabbity six 79 | return pass; // anything else 80 | default: assert(0); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /jni/pachi/tactics/nakade.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_TACTICS_NAKADE_H 2 | #define PACHI_TACTICS_NAKADE_H 3 | 4 | /* Piercing eyes. */ 5 | 6 | #include "board.h" 7 | #include "debug.h" 8 | 9 | /* Find an eye-piercing point within the @around area of empty board 10 | * internal to group of color @color. 11 | * Returns pass if the area is not a nakade shape or not internal. */ 12 | coord_t nakade_point(struct board *b, coord_t around, enum stone color); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /jni/pachi/tactics/nlib.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define DEBUG 6 | #include "board.h" 7 | #include "debug.h" 8 | #include "mq.h" 9 | #include "tactics/2lib.h" 10 | #include "tactics/nlib.h" 11 | #include "tactics/selfatari.h" 12 | 13 | 14 | void 15 | group_nlib_defense_check(struct board *b, group_t group, enum stone to_play, struct move_queue *q, int tag) 16 | { 17 | enum stone color = to_play; 18 | assert(color != S_OFFBOARD && color != S_NONE 19 | && color == board_at(b, group_base(group))); 20 | 21 | if (DEBUGL(5)) 22 | fprintf(stderr, "[%s] nlib defense check of color %d\n", 23 | coord2sstr(group, b), color); 24 | 25 | #if 0 26 | /* XXX: The code below is specific for 3-liberty groups. Its impact 27 | * needs to be tested first, and possibly moved to a more appropriate 28 | * place. */ 29 | 30 | /* First, look at our liberties. */ 31 | int continuous = 0, enemy = 0, spacy = 0, eyes = 0; 32 | for (int i = 0; i < 3; i++) { 33 | coord_t c = board_group_info(b, group).lib[i]; 34 | eyes += board_is_one_point_eye(b, c, to_play); 35 | continuous += coord_is_adjecent(c, board_group_info(b, group).lib[(i + 1) % 3], b); 36 | enemy += neighbor_count_at(b, c, stone_other(color)); 37 | spacy += immediate_liberty_count(b, c) > 1; 38 | } 39 | 40 | /* Safe groups are boring. */ 41 | if (eyes > 1) 42 | return; 43 | 44 | /* If all our liberties are in single line and they are internal, 45 | * this is likely a tiny three-point eyespace that we rather want 46 | * to live at! */ 47 | assert(continuous < 3); 48 | if (continuous == 2 && !enemy && spacy == 1) { 49 | assert(!eyes); 50 | int i; 51 | for (i = 0; i < 3; i++) 52 | if (immediate_liberty_count(b, board_group_info(b, group).lib[i]) == 2) 53 | break; 54 | /* Play at middle point. */ 55 | mq_add(q, board_group_info(b, group).lib[i], tag); 56 | mq_nodup(q); 57 | return; 58 | } 59 | #endif 60 | 61 | /* "Escaping" (gaining more liberties) with many-liberty group 62 | * is difficult. Do not even try. */ 63 | 64 | /* There is another way to gain safety - through winning semeai 65 | * with another group. */ 66 | /* We will not look at taking liberties of enemy n-groups, since 67 | * we do not try to gain liberties for own n-groups. That would 68 | * be really unbalanced (and most of our liberty-taking moves 69 | * would be really stupid, most likely). */ 70 | 71 | /* However, it is possible that we must start capturing a 2-lib 72 | * neighbor right now, because of approach liberties. Therefore, 73 | * we will check for this case. If we take a liberty of a group 74 | * even if we could have waited another move, no big harm done 75 | * either. */ 76 | 77 | foreach_in_group(b, group) { 78 | foreach_neighbor(b, c, { 79 | if (board_at(b, c) != stone_other(color)) 80 | continue; 81 | group_t g2 = group_at(b, c); 82 | if (board_group_info(b, g2).libs != 2) 83 | continue; 84 | can_atari_group(b, g2, stone_other(color), to_play, q, tag, true /* XXX */); 85 | }); 86 | } foreach_in_group_end; 87 | } 88 | -------------------------------------------------------------------------------- /jni/pachi/tactics/nlib.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_TACTICS_NLIB_H 2 | #define PACHI_TACTICS_NLIB_H 3 | 4 | /* N-liberty semeai defense tactical checks. */ 5 | 6 | #include "board.h" 7 | #include "debug.h" 8 | 9 | struct move_queue; 10 | 11 | void group_nlib_defense_check(struct board *b, group_t group, enum stone to_play, struct move_queue *q, int tag); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /jni/pachi/tactics/selfatari.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_TACTICS_SELFATARI_H 2 | #define PACHI_TACTICS_SELFATARI_H 3 | 4 | /* A fairly reliable elf-atari detector. */ 5 | 6 | #include "board.h" 7 | #include "debug.h" 8 | 9 | /* Check if this move is undesirable self-atari (resulting group would have 10 | * only single liberty and not capture anything; ko is allowed); we mostly 11 | * want to avoid these moves. The function actually does a rather elaborate 12 | * tactical check, allowing self-atari moves that are nakade, eye falsification 13 | * or throw-ins. */ 14 | static bool is_bad_selfatari(struct board *b, enum stone color, coord_t to); 15 | 16 | /* Move (color, coord) is a selfatari; this means that it puts a group of 17 | * ours in atari; i.e., the group has two liberties now. Return the other 18 | * liberty of such a troublesome group (optionally stored at *bygroup) 19 | * if that one is not a self-atari. 20 | * (In case (color, coord) is a multi-selfatari, consider a randomly chosen 21 | * candidate.) */ 22 | coord_t selfatari_cousin(struct board *b, enum stone color, coord_t coord, group_t *bygroup); 23 | 24 | 25 | bool is_bad_selfatari_slow(struct board *b, enum stone color, coord_t to); 26 | static inline bool 27 | is_bad_selfatari(struct board *b, enum stone color, coord_t to) 28 | { 29 | /* More than one immediate liberty, thumbs up! */ 30 | if (immediate_liberty_count(b, to) > 1) 31 | return false; 32 | 33 | return is_bad_selfatari_slow(b, color, to); 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /jni/pachi/tools/autobook/README: -------------------------------------------------------------------------------- 1 | This is a shell-based UCT implementation. ;-) 2 | 3 | From another perspective, this is a tool for automated opening book 4 | construction. The book is based on UCT tree with large exploration 5 | coefficient and fed with results from games against a compenent 6 | opponent. 7 | 8 | The UCT tree is stored in a directory tree, directories are nodes, 9 | UCT statistics are stored in the 'stats' file of each directory 10 | (first line is # of wins, second is # of playouts). Start the book 11 | building by running the 12 | 13 | autobook.sh PACHI_CMD OPPONENT_CMD BOOKDIR 14 | 15 | script, specifying complete Pachi and opponent's invocation details 16 | in the two parameters. If BOOKDIR exists, autobook.sh will continue 17 | an existing opening book build; multiple autobook.sh scripts may 18 | be running too. Just break it (Ctrl-C) when you want to stop. 19 | 20 | These helper scripts are used by autobook.sh: 21 | 22 | walk.sh A single iteration of the algorithm 23 | eval.sh Choose next move to choose in the current directory (node) 24 | expand.sh Create subdirectories (followup nodes) in the cwd 25 | 26 | The built autobook can be converted to an opening book in the fbook 27 | format (on the most-simulated basis) using: 28 | 29 | autobook2fbook.sh BOOKDIR 30 | -------------------------------------------------------------------------------- /jni/pachi/tools/autobook/autobook.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ $# -ne 3 ]; then 4 | echo "Usage: $0 PLAYER1 PLAYER2 BOOKDIR" >&2 5 | exit 1 6 | fi 7 | 8 | export CMDDIR=$(pwd) 9 | export SEQDIR=$(mktemp -d) 10 | 11 | if [ ! -d "$3" ]; then 12 | mkdir "$3" 13 | { echo 12; echo 24; } >"$3"/stats 14 | fi 15 | 16 | while true; do 17 | (cd "$3"; "$CMDDIR"/walk.sh "$1" "$2") 18 | sleep 5 19 | done 20 | -------------------------------------------------------------------------------- /jni/pachi/tools/autobook/autobook2fbook.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Config: 4 | # Minimal number of simulations for the result to be considered trustworthy 5 | min_sims=50 6 | 7 | if [ $# -ne 1 ]; then 8 | echo "Usage: $0 BOOKDIR" >&2 9 | exit 1 10 | fi 11 | 12 | export CMDDIR=$(pwd) 13 | 14 | scan() { 15 | seq="$1" 16 | for i in */; do echo $(sed -ne 2p $i/stats) $i; done | sort -rn | 17 | { first=1 18 | while read sims move; do 19 | move="${move%/}" 20 | if [ "$sims" -lt "$min_sims" ]; then 21 | break; 22 | fi 23 | [ -z "$first" ] || echo "$seq | $move" 24 | first= 25 | (cd "$move"; scan "$seq $move") 26 | done 27 | } 28 | } 29 | 30 | cd "$1" 31 | scan "" 32 | -------------------------------------------------------------------------------- /jni/pachi/tools/autobook/eval.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Choose next move to choose in the current directory (node) 4 | 5 | # Config: 6 | # Exploration coefficient 7 | explore_p=0.8 8 | 9 | best_move= 10 | best_val=-9999 11 | 12 | { read mwins; read msims; } "$move"/stats 25 | done 26 | -------------------------------------------------------------------------------- /jni/pachi/tools/autobook/walk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # A single iteration of the algorithm 4 | 5 | # Config: 6 | # After how many visits (including prior_sims!) a node is expanded. 7 | expand_sims=26 8 | # Virtual loss 9 | vloss=4 10 | # Twogtp path 11 | twogtp_path=/home/pasky/gogui-1.3.2/bin/gogui-twogtp 12 | 13 | # Expected env: 14 | # $CMDDIR 15 | # $SEQDIR 16 | 17 | pachi="$1"; shift 18 | opponent="$1" 19 | 20 | seq="" 21 | color=W 22 | while true; do 23 | { read wins; read sims; } stats.new 26 | mv stats.new stats # atomic 27 | 28 | children=$(find . -maxdepth 1 -type d | wc -l); 29 | case $children in 30 | 1) expanded=;; 31 | *) expanded=1;; 32 | esac 33 | 34 | if [ -z "$expanded" -a "$sims" -ge "$expand_sims" ]; then 35 | echo "(;FF[4]GM[1]CA[UTF-8]RU[Chinese]SZ[9]HA[0]KM[7.5]PW[white]PB[black]$seq)" >"$SEQDIR/a.sgf" 36 | "$CMDDIR"/expand.sh "$pachi" 37 | expanded=1 38 | fi 39 | if [ -z "$expanded" ]; then 40 | break; 41 | fi 42 | 43 | move=$("$CMDDIR"/eval.sh) 44 | 45 | cd "$move" 46 | case $color in 47 | B) color=W;; 48 | W) color=B;; 49 | esac 50 | 51 | sgfmove=$(echo "$move" | perl -nle 'my ($x,$y) = /(.)(.)/; $x=lc($x); $x=chr(ord($x)-1) if ord(lc $x) > ord("i"); $y = chr(96+10-$y); print "$x$y"') 52 | seq="$seq;${color}[$sgfmove]" 53 | done 54 | 55 | echo " *** Sequence: $seq" 56 | echo "(;FF[4]GM[1]CA[UTF-8]RU[Chinese]SZ[9]HA[0]KM[7.5]PW[white]PB[black]$seq)" >"$SEQDIR/a.sgf" 57 | rm -f "$SEQDIR"/r* 58 | 59 | # last move has been... - we want to simulate this being _our_ move yet, 60 | # i.e. start the simulation with the opponent to play 61 | case $color in 62 | B) 63 | black="$pachi" 64 | white="$opponent";; 65 | W) 66 | black="$opponent" 67 | white="$pachi";; 68 | esac 69 | $twogtp_path -black "$black" -white "$white" -auto -verbose -size 9 -komi 7.5 -sgffile "$SEQDIR/r" -games 1 -openings "$SEQDIR" 70 | wincolor=$(cat "$SEQDIR"/r-0.sgf | sed -ne 's/.*RE\[\(.\).*/\1/p') 71 | case $wincolor in 72 | B) result=1;; 73 | W) result=0;; 74 | esac 75 | echo " *** Result: $wincolor wins => $result" 76 | pwd; ls 77 | 78 | while [ -e stats ]; do 79 | case $color in 80 | B) nresult=$result;; 81 | W) nresult=$((1-result)); 82 | esac 83 | echo " + Recording $nresult .. $(pwd) color $color" 84 | 85 | { read wins; read sims; } stats.new 89 | mv stats.new stats # atomic 90 | 91 | cd .. 92 | case $color in 93 | B) color=W;; 94 | W) color=B;; 95 | esac 96 | done 97 | -------------------------------------------------------------------------------- /jni/pachi/tools/complete-tromptaylor.gtp: -------------------------------------------------------------------------------- 1 | boardsize 9 2 | komi 7.5 3 | clear_board 4 | play B f5 5 | play W d7 6 | play B e6 7 | play W c5 8 | play B e7 9 | play W d3 10 | play B e8 11 | play W f3 12 | play B e3 13 | play W g4 14 | play B f4 15 | play W e4 16 | play B e2 17 | play W d4 18 | play B g3 19 | play W h4 20 | play B f2 21 | play W g6 22 | play B d8 23 | play W d6 24 | play B e5 25 | play W d5 26 | play B d2 27 | play W g5 28 | play B c8 29 | play W f7 30 | play B c2 31 | play W f8 32 | play B c7 33 | play W e9 34 | play B b6 35 | play W d9 36 | play B b5 37 | play W c9 38 | play B b7 39 | play W h3 40 | play B g2 41 | play W h2 42 | play B a8 43 | play W g1 44 | play B b4 45 | play W f1 46 | play B e1 47 | play W h1 48 | play B a7 49 | play W b9 50 | play B b2 51 | play W a9 52 | play B a4 53 | play W f9 54 | play B a6 55 | play W pass 56 | play B a3 57 | play W pass 58 | play B a5 59 | play W pass 60 | play B a2 61 | play W pass 62 | play B a1 63 | play W pass 64 | play B c3 65 | play W pass 66 | play B pass 67 | -------------------------------------------------------------------------------- /jni/pachi/tools/complete.gtp: -------------------------------------------------------------------------------- 1 | boardsize 9 2 | 3 | clear_board 4 | 5 | komi 7.5 6 | 7 | 8 | play b C4 9 | 10 | 11 | play w E5 12 | 13 | play b C6 14 | 15 | 16 | play w E6 17 | 18 | play b D3 19 | 20 | 21 | play w F4 22 | 23 | play b D7 24 | 25 | 26 | play w E7 27 | 28 | play b E4 29 | 30 | 31 | play w E3 32 | 33 | play b D4 34 | 35 | 36 | play w F3 37 | 38 | play b D5 39 | 40 | 41 | play w F5 42 | 43 | play b D6 44 | 45 | 46 | play w E8 47 | 48 | play b D2 49 | 50 | 51 | play w D8 52 | 53 | play b C8 54 | 55 | 56 | play w E2 57 | 58 | play b D9 59 | 60 | 61 | play w H5 62 | 63 | play b E1 64 | 65 | 66 | play w G2 67 | 68 | play b E9 69 | 70 | 71 | play w F8 72 | 73 | play b F9 74 | 75 | 76 | play w G9 77 | 78 | play b C9 79 | 80 | 81 | play w G8 82 | 83 | play b G1 84 | 85 | 86 | play w H2 87 | 88 | play b F1 89 | 90 | 91 | play w J2 92 | 93 | play b H1 94 | 95 | 96 | play w G3 97 | 98 | play b J1 99 | 100 | 101 | play w G6 102 | 103 | play b D1 104 | 105 | 106 | play w H4 107 | 108 | play b PASS 109 | 110 | 111 | play w H7 112 | 113 | play b PASS 114 | 115 | 116 | play w A2 117 | 118 | play b B2 119 | 120 | 121 | play w A1 122 | 123 | play b A3 124 | 125 | 126 | play w A5 127 | 128 | play b B1 129 | 130 | 131 | play w A2 132 | 133 | play b A1 134 | 135 | 136 | play w A4 137 | 138 | play b B4 139 | 140 | 141 | play w A7 142 | 143 | play b B5 144 | 145 | 146 | play w A6 147 | 148 | play b B6 149 | 150 | 151 | play w pass 152 | 153 | play b B7 154 | 155 | 156 | play w B8 157 | 158 | play b A8 159 | 160 | 161 | play w G5 162 | 163 | play b B9 164 | 165 | 166 | play w F2 167 | 168 | play b PASS 169 | 170 | 171 | play w C2 172 | 173 | play b C3 174 | 175 | 176 | play w H8 177 | 178 | play b C1 179 | 180 | 181 | play w A4 182 | 183 | play b A5 184 | 185 | 186 | play w A7 187 | 188 | play b A6 189 | 190 | 191 | play w F6 192 | 193 | play b PASS 194 | 195 | 196 | play w F7 197 | 198 | play b PASS 199 | 200 | 201 | play w G4 202 | 203 | play b PASS 204 | 205 | 206 | play w H6 207 | 208 | play b PASS 209 | 210 | 211 | play w J4 212 | 213 | play b PASS 214 | 215 | 216 | play w G7 217 | 218 | play b PASS 219 | 220 | 221 | play w J9 222 | 223 | play b PASS 224 | 225 | 226 | play w H9 227 | 228 | play b PASS 229 | 230 | 231 | play w J6 232 | 233 | play b PASS 234 | 235 | 236 | play w H3 237 | 238 | play b PASS 239 | 240 | 241 | play w J3 242 | 243 | play b PASS 244 | 245 | 246 | play w J7 247 | 248 | play b PASS 249 | 250 | 251 | genmove w 252 | 253 | -------------------------------------------------------------------------------- /jni/pachi/tools/genmove.gtp: -------------------------------------------------------------------------------- 1 | boardsize 9 2 | clear_board 3 | komi 7.5 4 | genmove black 5 | genmove white 6 | -------------------------------------------------------------------------------- /jni/pachi/tools/genmove19.gtp: -------------------------------------------------------------------------------- 1 | boardsize 19 2 | clear_board 3 | komi 7.5 4 | genmove black 5 | genmove white 6 | -------------------------------------------------------------------------------- /jni/pachi/tools/gentbook.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | size="$1" # board size 3 | opts="$2" # UCT engine options; must NOT specify different policy 4 | popts="$3" # UCT policy options 5 | [ -n "$size" ] || size=9 6 | [ -z "$opts" ] || opts=",$opts" 7 | [ -z "$popts" ] || popts=":$popts" 8 | 9 | if [ "$size" -le 13 ]; then 10 | games=400000 11 | else 12 | games=200000 13 | fi 14 | 15 | rm ucttbook-$size-7.5.pachitree 16 | n=0 17 | gentbook1() 18 | { 19 | echo "[#$n:$1]" 20 | n=$((n+1)) 21 | echo -e 'boardsize '$size'\nclear_board\nkomi 7.5\npachi-gentbook b' | 22 | ./pachi -t =$games "policy=ucb1amaf:explore_p=$1$popts$opts" 23 | } 24 | gentbook1 0.0 25 | gentbook1 0.1 26 | gentbook1 0.2 27 | gentbook1 2.0 28 | gentbook1 0.2 29 | gentbook1 2.0 30 | gentbook1 0.1 31 | gentbook1 0.0 32 | gentbook1 0.0 33 | gentbook1 0.0 34 | -------------------------------------------------------------------------------- /jni/pachi/tools/kgslog2gtp.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -ln 2 | # 3 | # kgslog2gtp - Convert kgsGtp log file to GTP command stream 4 | # 5 | # The command stream contains two special GTP commands intended 6 | # for further script processing (unrecognized by Pachi itself): 7 | # 8 | # pachi-mygame COLOR OPPONENT DATE TIME 9 | # pachi-mymove COORD VALUE 10 | # 11 | # (You probably want to convert pachi-mymove to play.) 12 | 13 | chomp; 14 | 15 | # 19.1.2012 20:47:47 com.gokgs.client.gtp.a 16 | if (s/^(\S+ \S+) com.gokgs.client.gtp.a $/$1/) { 17 | $a = $1; 18 | 19 | # FINE: Starting game as white against Mateman 20 | } elsif (s/^FINE:.*as (\S+) against (\w+)/$1 $2/) { 21 | print "pachi-mygame $_ $a"; 22 | 23 | # IN: play b o3 24 | } elsif (s/^IN: // and not /genmove/ and not /kgs-chat/ and not /time/) { 25 | print $_; 26 | 27 | # *** WINNER is C4 (3,4) with score 0.4333 (49243/93153:93153/93393 games), extra komi 0.000000 28 | } elsif (s/^\*\*\* WINNER is (\S+) .*score (\S+) .*komi 0\.0.*/$1 $2/) { 29 | print "pachi-mymove $_"; 30 | } 31 | -------------------------------------------------------------------------------- /jni/pachi/tools/pattern3_show.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # ./pattern3_show.pl PATNUM 3 | 4 | use warnings; 5 | no warnings "qw"; 6 | use strict; 7 | 8 | my $pat = shift @ARGV; 9 | my @s = qw(. X O #); 10 | 11 | my @p = map { ($pat >> (2*$_)) & 3 } (0..7); 12 | splice @p, 4, 0, (0); 13 | for my $y (0..2) { 14 | for my $x (reverse 0..2) { 15 | print $s[$p[$x + $y*3]]; 16 | } 17 | print "\n"; 18 | } 19 | -------------------------------------------------------------------------------- /jni/pachi/tools/pattern_bayes_gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # pattern_bayes_gen: Generate pattern probability table from a SGF collection 3 | # (or stdin GTP stream). 4 | 5 | (if [ x"$1" = x"-" ]; then cat; else for i in "$@"; do echo $i >&2; tools/sgf2gtp.pl <$i; done; fi) | 6 | ./pachi -d 0 -e patternscan competition,spat_split_sizes | 7 | perl -nle ' 8 | BEGIN { use List::MoreUtils qw(uniq); } 9 | 10 | s/^= // or next; 11 | chomp; 12 | my ($winner, $witness) = (/^\[(.*)\] \[(.*)\]$/); 13 | 14 | sub parse { $_ = $_[0]; s/\) \(/),(/g; return split(/,/); } 15 | 16 | for (uniq(parse($winner))) { 17 | $choices{$_}++; 18 | } 19 | for (uniq(parse($witness))) { 20 | $counts{$_}++; 21 | } 22 | 23 | END { 24 | for (keys %counts) { 25 | $p{$_} = $choices{$_} / $counts{$_}; 26 | } 27 | for (sort { $counts{$a} <=> $counts{$b} } keys %p) { 28 | next if ($counts{$_} < 2); 29 | printf("%.3f %d %d %s\n", $p{$_}, $choices{$_}, $counts{$_}, $_); 30 | } 31 | }' 32 | -------------------------------------------------------------------------------- /jni/pachi/tools/pattern_bayes_merge.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # pattern_bayes_merge: Merge pattern probability tables; pass them 3 | # as arguments. 4 | 5 | cat "$@" | perl -nle ' 6 | chomp; 7 | my ($p, $ch, $co, $pa) = /^(.*?) (\d+) (\d+) (.*)$/; 8 | $pa or die "parse error: $_"; 9 | $choices{$pa} += $ch; 10 | $counts{$pa} += $co; 11 | 12 | END { 13 | for (keys %counts) { 14 | $p{$_} = $choices{$_} / $counts{$_}; 15 | } 16 | for (sort { $counts{$a} <=> $counts{$b} } keys %p) { 17 | next if ($counts{$_} < 2); 18 | printf("%.3f %d %d %s\n", $p{$_}, $choices{$_}, $counts{$_}, $_); 19 | } 20 | } 21 | ' 22 | -------------------------------------------------------------------------------- /jni/pachi/tools/pattern_byplayer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # pattern_byplayer - Build a per-player database of used patterns 3 | # 4 | # Invoke this script for each played game, it will add patterns 5 | # to the database incrementally; each file in the database contains 6 | # patterns played by one player. 7 | # 8 | # You must already have a spatial dictionary generated. 9 | 10 | dbdir="$1"; shift 11 | sgf="$1"; shift 12 | # rest of parameters is passed to the patternscan engine 13 | 14 | sgf_attr() { 15 | # TODO: Does not work correctly for attributes containing escaped ] 16 | # e.g. "PB[Tony \[Killer\] Nowak]" gets cropped to "Tony \[Killer" 17 | # Not a big problem, since usually the player name is just 18 | # [a-zA-Z0-9]* 19 | 20 | sed -n 's/^.*'$1'\[\([^]]*\)\].*$/\1/p' "$sgf" 21 | } 22 | 23 | black="$(sgf_attr PB)" 24 | white="$(sgf_attr PW)" 25 | handi="$(sgf_attr HA)" 26 | 27 | if [ -n "$handi" ] && [ "$handi" -gt 0 ]; then 28 | to_play=white 29 | # Comment following out if you want to include handi games. 30 | echo "$sgf: Skipping handicap game" >&2 31 | exit 1 32 | fi 33 | 34 | to_play=black 35 | cat "$sgf" | tools/sgf2gtp.pl | ./pachi -d 0 -e patternscan "$@" | 36 | sed -n -e 's/^= //p' | grep -v '^ *$' | # skip irrelevant replies 37 | while read pattern; do 38 | if [ "$to_play" = black ]; then 39 | player="$black" 40 | to_play=white 41 | else 42 | player="$white" 43 | to_play=black 44 | fi 45 | echo "$pattern" >>"$dbdir/$player" 46 | done 47 | -------------------------------------------------------------------------------- /jni/pachi/tools/pattern_getdrops.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -n 2 | # 3 | # pattern_getdrops - Find significant value drops in kgslog GTP stream 4 | # and convert them to lead-in game records for pattern learning 5 | # 6 | # Run as pipeline: 7 | # tools/kgslog2gtp.pl | tools/pattern_getdrops.pl | tools/pattern_bayes_gen.sh - 8 | 9 | BEGIN { 10 | use vars qw(@game $lastval $valthres $valfrac); 11 | $valthres = 0.8; 12 | $valfrac = 0.95; 13 | } 14 | 15 | chomp; 16 | @_ = split(/\s+/); 17 | 18 | if ($_[0] eq 'pachi-mygame') { 19 | @game = @_[1..4]; 20 | print STDERR "*** new game [@game]\n"; 21 | $lastval = 0; 22 | @commands = (); 23 | 24 | } elsif ($_[0] eq 'pachi-mymove') { 25 | if ($lastval > 0 and $lastval < $valthres and $_[2] / $lastval < $valfrac) { 26 | print STDERR "large value drop $lastval -> $_[2] [@game :: @_]\n"; 27 | print "$_\n" for @commands; 28 | print "play $game[0] $_[1] 1\n"; 29 | } 30 | $lastval = $_[2]; 31 | my $cmd = "play $game[0] $_[1] 0 $_[2]"; 32 | push @commands, $cmd; 33 | 34 | } elsif ($_[0] eq 'play') { 35 | push @_, 0; 36 | push @commands, "@_"; 37 | 38 | } else { 39 | push @commands, "@_"; 40 | } 41 | -------------------------------------------------------------------------------- /jni/pachi/tools/pattern_spatial_gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # pattern_spatial_gen: Initialize spatial dictionary from a SGF collection 3 | # 4 | # We will first gather all spatial features from the SGF collection 5 | # (we take files as arguments) and store these occuring more than 4 times 6 | # in a freshly created spatial dictionary; afterwards, you will probably want 7 | # to do standard pattern-matching. 8 | # 9 | # DO NOT RUN THIS CONCURRENTLY! The dictionary will get corrupted. 10 | # 11 | # To get spatials in competion mode (also get information about unplayed 12 | # spatials present at the board, not just the single played one per move), 13 | # run this script as: 14 | # 15 | # PATARGS="competition" ./pattern_spatial_gen.sh ... 16 | # 17 | # Similarly, you can set SPATMIN to different number than 4 to include 18 | # spatial features with other number of occurences. 19 | 20 | [ -n "$SPATMIN" ] || SPATMIN=4 21 | 22 | rm -f patterns.spat 23 | 24 | echo " Gathering population of spatials occuring more than $SPATMIN times..." 25 | (for i in "$@"; do echo $i >&2; tools/sgf2gtp.pl <$i; done) | 26 | ./pachi -d 0 -e patternscan gen_spat_dict,no_pattern_match,spat_threshold=$SPATMIN${PATARGS:+,$PATARGS} >/dev/null 27 | 28 | echo " Renumbering patterns.spat..." 29 | perl -i -pe '/^#/ and next; s/^\d+/++$a/e' patterns.spat 30 | 31 | echo -n " Counting hash collisions... " 32 | perl -lne 'chomp; my ($id, $d, $p, @h) = split(/ /, $_); foreach (@h) { next if $h{$_} = $id; print "collision $id - $h{$_} ($_)" if $h{$_}; $h{$_}=$id; }' patterns.spat | wc -l 33 | -------------------------------------------------------------------------------- /jni/pachi/tools/pattern_spatial_show.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # pattern_spatial_show: Show given spatial dictionary entry on board 3 | 4 | my $f = "patterns.spat"; 5 | my $id = $ARGV[0]; 6 | 7 | my @ofs = (); 8 | 9 | open D, "$f" or die "$f: $!"; 10 | while () { 11 | chomp; 12 | if (s/^# Point order: d=(\d+) //) { 13 | my $d = $1; next if ($d < 1); 14 | # XXX: Distances must be in proper order! 15 | s/ *$//; 16 | push @ofs, map { [ split(/,/, $_) ] } split(/ /, $_); 17 | # print "#### $_\n"; 18 | # print "[$d] ($#ofs) " . join(' ', map { $_->[0].",".$_->[1] } @ofs) . "\n"; 19 | next; 20 | } 21 | /^#/ and next; 22 | my ($lid, $d, $pat, @hashes) = split (/\s+/, $_); 23 | if ($id == $lid) { 24 | print "$d $pat\n"; 25 | my @b; 26 | my @pc = split (//, $pat); 27 | for my $i (0 .. $#pc) { 28 | # print "$i: $pc[$i] -> $ofs[$i][1],$ofs[$i][0]\n"; 29 | $b[$d + $ofs[$i][1]][$d + $ofs[$i][0]] = $pc[$i]; 30 | } 31 | $b[$d][$d] = '_'; 32 | for my $y (0 .. 2 * $d) { 33 | for my $x (0 .. 2 * $d) { 34 | print $b[2 * $d - $y][$x] || ' '; 35 | print ' '; 36 | } 37 | print "\n"; 38 | } 39 | last; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /jni/pachi/tools/sgf-analyse.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # Simple script using Pachi for game analysis of SGF. 3 | # Pachi will analyse each move in the SGF and suggest the winrate 4 | # for either player and winrate it estimated for in-game followup. 5 | # 6 | # Usage: tools/sgf-analyse.pl COLOR SGF PACHIARGS... 7 | # 8 | # Note that this script assumes dynkomi=none and does not show 9 | # dynamic komi information. (Would be trivial to add but it's tricky 10 | # to interpret the data.) 11 | # 12 | # This script is dirty and insecure for untrusted input! 13 | # 14 | # Example: tools/sgf-analyse.pl W progame.sgf -t =2000 -d 0 dynkomi=none 15 | # ...to get 2000 simulations per move, and winrates from white perspective. 16 | # 17 | # To plot the output in gnuplot: 18 | # set yr [0:1] 19 | # set ytics 0,0.25,1 20 | # plot "datafile.csv" using 1:5 with lines 21 | 22 | use warnings; 23 | use strict; 24 | 25 | my $mcolor = shift @ARGV; 26 | my $sgf = shift @ARGV; 27 | 28 | sub one { 29 | my ($move) = @_; 30 | 31 | # Move of the other color - supposedly. 32 | return if ($move % 2 == ($mcolor eq 'B' ? 0 : 1)); 33 | 34 | # Get pachi output from GTP stream that contains the SGF up to 35 | # given move, with information about the originally made move 36 | # included. 37 | my $line = $move + 3; # board_size, clearboard, komi 38 | my $rest = $line + 1; 39 | open my $g, "tools/sgf2gtp.pl < \"$sgf\" | sed -e '$line s/play \\(.*\\) \\(.*\\)/1 echo \\1 \\2\\n2 genmove \\1\\n3 pachi-result/' -e '$rest,\$ d' | ./pachi @ARGV |" or die $!; 40 | 41 | # Parse the GTP output. 42 | my ($color, $realmove, $genmove, $winrate) = @_; 43 | while (<$g>) { 44 | chomp; 45 | if (/^=1 (.*) (.*)/) { 46 | $color = $1; $realmove = uc $2; 47 | } elsif (/^=2 (.*)/) { 48 | $genmove = $1; 49 | } elsif (/^=3 (.*) (.*) (.*) (.*)/) { 50 | $winrate = $mcolor eq $color ? $3 : 1.0 - $3; 51 | } 52 | } 53 | 54 | # Pass value is not interesting since Pachi might want 55 | # to clarify some groups yet. 56 | return if $realmove eq 'PASS'; 57 | 58 | # Generate summary line. 59 | print join(', ', $move, $color, $realmove, $genmove, $winrate) . "\n"; 60 | } 61 | 62 | print "# $sgf @ARGV\n"; 63 | 64 | my $moves = `tools/sgf2gtp.pl < \"$sgf\" | wc -l` - 3; 65 | one($_) for (1 .. $moves); 66 | -------------------------------------------------------------------------------- /jni/pachi/tools/sgf-ratemove.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Simple script using Pachi for rating all moves in a given situation. 3 | # Pachi will analyse each followup move and suggest a winrate for it; 4 | # higher is better. 5 | # 6 | # Usage: tools/sgf-ratemove.sh SGF MOVENUM PACHIARGS... 7 | # 8 | # Note that this script assumes dynkomi=none and does not show 9 | # dynamic komi information. (Would be trivial to add but it's tricky 10 | # to interpret the data.) 11 | # 12 | # This script is dirty and insecure for untrusted input! 13 | # 14 | # Example: tools/sgf-ratemove.sh progame.sgf 120 -t =500 -d 0 15 | # ...to get 500 simulations per each possible move in programe.sgf 16 | # at move 120. 17 | # 18 | # If you want to know more details on what is Pachi thinking about the 19 | # various moves, remove the `-d 0` part. To improve the accuracy of values 20 | # (at the expense of run time), raise the value of 500 (try 2000 or 10000; 21 | # 100000 will usually already take couple of hours). The values will be 22 | # most useful in the middle game; in fuseki and most yose situations, 23 | # expect a lot of noise. 24 | 25 | sgf=$1; shift 26 | movenum=$1; shift 27 | tools/sgf2gtp.pl -g -n $movenum <"$sgf" | 28 | sed -e 's/genmove/0 pachi-evaluate/' | 29 | ./pachi "$@" | 30 | sed -ne '/^=0/,${s/^=0 //;p}' | 31 | sort -r -n -t ' ' -k 2 32 | -------------------------------------------------------------------------------- /jni/pachi/tools/sgf2gtp.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -l 2 | # 3 | # sgf2gtp - Convert SGF game record to GTP command stream 4 | # 5 | # Usage: sgf2gtp [-g] [-n MOVENUM] [FILENAME] 6 | # 7 | # This is a naive Perl script that will convert SGF files to GTP 8 | # format so that you can feed them to Pachi, insert genmove at 9 | # the right places etc. Might not work on obscure SGF files, 10 | # and of course there must be no variations. 11 | # 12 | # When called with a filename argument, it will create the output 13 | # file with .gtp extension instead of .sgf. 14 | # 15 | # -g: Automatically append genmove command for the other color. 16 | # -n MOVENUM: Output at most first MOVENUM moves. 17 | 18 | use warnings; 19 | 20 | my $genmove; 21 | if ($ARGV[0] and $ARGV[0] eq '-g') { 22 | shift @ARGV; 23 | $genmove = 1; 24 | } 25 | 26 | my $maxmoves; 27 | if ($ARGV[0] and $ARGV[0] eq '-n') { 28 | shift @ARGV; 29 | $maxmoves = shift @ARGV; 30 | } 31 | 32 | if ($ARGV[0]) { 33 | open STDIN, "$ARGV[0]" or die "$ARGV[0]: $!"; 34 | my $ofile = $ARGV[0]; $ofile =~ s/sgf$//i; $ofile .= 'gtp'; 35 | open STDOUT, ">$ofile" or die "$ofile: $!"; 36 | } 37 | 38 | local $/ = undef; my $sgf = <>; 39 | my $size = ($sgf =~ /SZ\[(\d+)\]/)[0]; 40 | $size ||= 19; 41 | $sgf =~ s/\bC\[.*?\]//gs; # no comments 42 | #$sgf =~ s/\).*//gs; # cut at end of principal branch 43 | 44 | print "boardsize " . $size; 45 | print "clear_board"; 46 | if ($sgf =~ s/\bKM\[([\d.]+)\]//gs) { 47 | print "komi $1"; 48 | } 49 | if ($sgf =~ s/\bHA\[(\d+)\]//gs and $1 > 0) { 50 | print "fixed_handicap $1"; 51 | } 52 | 53 | my $abcd = "abcdefghijklmnopqrstuvwxyz"; 54 | my $movenum = 0; 55 | my $last_color = 'w'; 56 | 57 | my @m = split /;/, $sgf; 58 | foreach (@m) { 59 | $maxmoves and $movenum >= $maxmoves and last; 60 | 61 | if (/^([BW])\[\]/) { 62 | $last_color = $1; 63 | $movenum++; 64 | print "play $1 pass"; 65 | next; 66 | } 67 | unless (/^([BW])\[(\w\w)\]/) { 68 | next; 69 | } 70 | 71 | my ($color, $coord) = ($1, $2); 72 | my ($x, $y) = split //, $coord; 73 | ($x ge 'i') and $x++; 74 | $y = $size - index($abcd, $y); 75 | 76 | $last_color = $color; 77 | $movenum++; 78 | print "play $color $x$y"; 79 | } 80 | 81 | if ($genmove) { 82 | print "genmove ".(uc $last_color eq 'W' ? 'B' : 'W'); 83 | } 84 | -------------------------------------------------------------------------------- /jni/pachi/tools/sgflib/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | -------------------------------------------------------------------------------- /jni/pachi/tools/sgflib/__init__.py: -------------------------------------------------------------------------------- 1 | from sgflib import * 2 | -------------------------------------------------------------------------------- /jni/pachi/tools/spirit.gtp: -------------------------------------------------------------------------------- 1 | # Spirit-gman KGS 2007-03-07 19:14 2 | boardsize 9 3 | komi 0.5 4 | clear_board 5 | play b d6 6 | play w d3 7 | play b d4 8 | play w c4 9 | # !! 10 | play b e3 11 | play w e2 12 | # !! 13 | play b c3 14 | play w d2 15 | play b c5 16 | play w b4 17 | # !! 18 | play b e7 19 | play w g5 20 | # !! do you see e4 reply? 21 | play b f2 22 | play w e4 23 | play b f7 24 | play w b5 25 | play b d5 26 | play w f3 27 | play b b6 28 | play w h7 29 | play b b3 30 | play w b2 31 | play b g6 32 | play w h6 33 | # this should be better a4 34 | play b a3 35 | play w a2 36 | # !! are we seeing the a2 atari threat? 37 | play b h5 38 | -------------------------------------------------------------------------------- /jni/pachi/uct/Makefile: -------------------------------------------------------------------------------- 1 | INCLUDES=-I.. 2 | OBJS=dynkomi.o tree.o uct.o prior.o search.o slave.o walk.o plugins.o 3 | 4 | all: uct.a 5 | uct.a: $(OBJS) 6 | 7 | clean: 8 | rm -f *.o *.a 9 | clean-profiled: 10 | rm -f *.gcda *.gcno 11 | 12 | -include ../Makefile.lib 13 | -------------------------------------------------------------------------------- /jni/pachi/uct/dynkomi.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_UCT_DYNKOMI_H 2 | #define PACHI_UCT_DYNKOMI_H 3 | 4 | /* Dynamic computation of artificial komi values to stabilize the MCTS. */ 5 | 6 | #include "move.h" 7 | #include "uct/internal.h" 8 | #include "uct/tree.h" 9 | 10 | /* Motivation: Monte Carlo Tree Search tends to produce unstable and 11 | * unreasonable results when playing in situation of extreme advantage 12 | * or * disadvantage, due to poor move selection becauce of low 13 | * signal-to-noise * ratio; notably, this occurs when playing in high 14 | * handicap game, burdening the computer with further disadvantage 15 | * against the strong human opponent. */ 16 | 17 | /* Here, we try to solve the problem by adding arbitrarily computed 18 | * komi values to the score. The used algorithm is transparent to the 19 | * rest of UCT implementation. */ 20 | 21 | struct board; 22 | struct tree; 23 | struct tree_node; 24 | struct uct; 25 | struct uct_dynkomi; 26 | 27 | /* Compute effective komi value for given color: Positive value 28 | * means giving komi, negative value means taking komi. */ 29 | #define komi_by_color(komi, color) ((color) == S_BLACK ? (komi) : -(komi)) 30 | 31 | /* Determine base dynamic komi for this genmove run. The returned 32 | * value is stored in tree->extra_komi and by itself used just for 33 | * user information. */ 34 | typedef floating_t (*uctd_permove)(struct uct_dynkomi *d, struct board *b, struct tree *tree); 35 | /* Determine actual dynamic komi for this simulation (run on board @b 36 | * from node @node). In some cases, this function will just return 37 | * tree->extra_komi, in other cases it might want to adjust the komi 38 | * according to the actual move depth. */ 39 | typedef floating_t (*uctd_persim)(struct uct_dynkomi *d, struct board *b, struct tree *tree, struct tree_node *node); 40 | /* Destroy the uct_dynkomi structure. */ 41 | typedef void (*uctd_done)(struct uct_dynkomi *d); 42 | 43 | struct uct_dynkomi { 44 | struct uct *uct; 45 | uctd_permove permove; 46 | uctd_persim persim; 47 | uctd_done done; 48 | void *data; 49 | 50 | /* Game state for dynkomi use: */ 51 | /* Information on average score at the simulation end (black's 52 | * perspective) since last dynkomi adjustment. */ 53 | struct move_stats score; 54 | /* Information on average winrate of simulations since last 55 | * dynkomi adjustment. */ 56 | struct move_stats value; 57 | }; 58 | 59 | struct uct_dynkomi *uct_dynkomi_init_none(struct uct *u, char *arg, struct board *b); 60 | struct uct_dynkomi *uct_dynkomi_init_linear(struct uct *u, char *arg, struct board *b); 61 | struct uct_dynkomi *uct_dynkomi_init_adaptive(struct uct *u, char *arg, struct board *b); 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /jni/pachi/uct/plugins.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_UCT_PLUGINS_H 2 | #define PACHI_UCT_PLUGINS_H 3 | 4 | struct tree_node; 5 | struct board; 6 | struct prior_map; 7 | 8 | 9 | /* The pluginset structure of current UCT context. */ 10 | struct uct_pluginset; 11 | struct uct_pluginset *pluginset_init(struct board *b); 12 | void pluginset_done(struct uct_pluginset *ps); 13 | 14 | /* Load a new plugin with DLL at path, passed arguments in args. */ 15 | void plugin_load(struct uct_pluginset *ps, char *path, char *args); 16 | 17 | /* Query plugins for priors of a node's leaves. */ 18 | void plugin_prior(struct uct_pluginset *ps, struct tree_node *node, struct prior_map *map, int eqex); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /jni/pachi/uct/policy/Makefile: -------------------------------------------------------------------------------- 1 | INCLUDES=-I../.. 2 | OBJS=generic.o ucb1.o ucb1amaf.o 3 | 4 | all: uctpolicy.a 5 | uctpolicy.a: $(OBJS) 6 | 7 | clean: 8 | rm -f *.o *.a 9 | clean-profiled: 10 | rm -f *.gcda *.gcno 11 | 12 | -include ../../Makefile.lib 13 | -------------------------------------------------------------------------------- /jni/pachi/uct/policy/generic.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "board.h" 7 | #include "debug.h" 8 | #include "move.h" 9 | #include "tactics/util.h" 10 | #include "random.h" 11 | #include "uct/internal.h" 12 | #include "uct/tree.h" 13 | #include "uct/policy/generic.h" 14 | 15 | struct tree_node * 16 | uctp_generic_choose(struct uct_policy *p, struct tree_node *node, struct board *b, enum stone color, coord_t exclude) 17 | { 18 | struct tree_node *nbest = node->children; 19 | if (!nbest) return NULL; 20 | struct tree_node *nbest2 = nbest->sibling; 21 | 22 | /* This function is called while the tree is updated by other threads. 23 | * We rely on node->children being set only after the node has been fully expanded. */ 24 | for (struct tree_node *ni = nbest2; ni; ni = ni->sibling) { 25 | // we compare playouts and choose the best-explored 26 | // child; comparing values is more brittle 27 | if (node_coord(ni) == exclude || ni->hints & TREE_HINT_INVALID) 28 | continue; 29 | if (ni->u.playouts > nbest->u.playouts) { 30 | nbest2 = nbest; 31 | nbest = ni; 32 | } else if (ni->u.playouts > nbest2->u.playouts) { 33 | nbest2 = ni; 34 | } 35 | } 36 | /* Play pass only if we can afford scoring. Call expensive uct_pass_is_safe() only if 37 | * pass is indeed the best move. */ 38 | if (is_pass(node_coord(nbest)) && !uct_pass_is_safe(p->uct, b, color, p->uct->pass_all_alive)) 39 | return nbest2; 40 | return nbest; 41 | } 42 | 43 | /* Return the node with best value instead of best explored. We must use the heuristic 44 | * value (using prior and possibly rave), because the raw value is meaningless for 45 | * nodes evaluated rarely. 46 | * This function is called while the tree is updated by other threads */ 47 | void 48 | uctp_generic_winner(struct uct_policy *p, struct tree *tree, struct uct_descent *descent) 49 | { 50 | if (!p->evaluate) 51 | return; 52 | bool allow_pass = false; /* At worst forces some extra playouts at the end */ 53 | int parity = tree_node_parity(tree, descent->node); 54 | 55 | uctd_try_node_children(tree, descent, allow_pass, parity, p->uct->tenuki_d, di, urgency) { 56 | urgency = p->evaluate(p, tree, &di, parity); 57 | } uctd_set_best_child(di, urgency); 58 | 59 | uctd_get_best_child(descent); 60 | } 61 | -------------------------------------------------------------------------------- /jni/pachi/uct/prior.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_UCT_PRIOR_H 2 | #define PACHI_UCT_PRIOR_H 3 | 4 | #include "move.h" 5 | #include "uct/tree.h" 6 | 7 | struct tree; 8 | struct tree_node; 9 | struct uct; 10 | struct board; 11 | 12 | struct prior_map { 13 | struct board *b; 14 | enum stone to_play; 15 | int parity; 16 | /* [board_size2(b)] array, move_stats are the prior 17 | * values to be assigned to individual moves; 18 | * move_stats.value is not updated. */ 19 | struct move_stats *prior; 20 | /* [board_size2(b)] array, whether to compute 21 | * prior for the given value. */ 22 | bool *consider; 23 | /* [board_size2(b)] array from cfg_distances() */ 24 | int *distances; 25 | }; 26 | 27 | /* @value is the value, @playouts is its weight. */ 28 | static void add_prior_value(struct prior_map *map, coord_t c, floating_t value, int playouts); 29 | 30 | void uct_prior(struct uct *u, struct tree_node *node, struct prior_map *map); 31 | 32 | struct uct_prior; 33 | struct uct_prior *uct_prior_init(char *arg, struct board *b, struct uct *u); 34 | void uct_prior_done(struct uct_prior *p); 35 | 36 | 37 | static inline void 38 | add_prior_value(struct prior_map *map, coord_t c, floating_t value, int playouts) 39 | { 40 | floating_t v = map->parity > 0 ? value : 1 - value; 41 | /* We don't need atomicity: */ 42 | struct move_stats s = { .playouts = playouts, .value = v }; 43 | stats_merge(&map->prior[c], &s); 44 | } 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /jni/pachi/uct/search.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_UCT_SEARCH_H 2 | #define PACHI_UCT_SEARCH_H 3 | 4 | /* MCTS Search infrastructure. We juggle the search threads and 5 | * control search duration. */ 6 | 7 | /* uct.c provides the GTP interface and engine setup. */ 8 | /* walk.c controls repeated walking of the MCTS tree within 9 | * the search threads. */ 10 | 11 | #include // sig_atomic_t 12 | 13 | #include "debug.h" 14 | #include "move.h" 15 | #include "ownermap.h" 16 | #include "playout.h" 17 | #include "timeinfo.h" 18 | #include "uct/internal.h" 19 | 20 | struct tree; 21 | struct tree_node; 22 | 23 | /* Internal UCT structures */ 24 | 25 | /* How often to inspect the tree from the main thread to check for playout 26 | * stop, progress reports, etc. (in seconds) */ 27 | #define TREE_BUSYWAIT_INTERVAL 0.1 /* 100ms */ 28 | 29 | 30 | /* Thread manager state */ 31 | extern volatile sig_atomic_t uct_halt; 32 | extern bool thread_manager_running; 33 | 34 | /* Search thread context */ 35 | struct uct_thread_ctx { 36 | int tid; 37 | struct uct *u; 38 | struct board *b; 39 | enum stone color; 40 | struct tree *t; 41 | unsigned long seed; 42 | int games; 43 | struct time_info *ti; 44 | }; 45 | 46 | 47 | /* Progress information of the on-going MCTS search - when did we 48 | * last adjusted dynkomi, printed out stuff, etc. */ 49 | struct uct_search_state { 50 | /* Number of games simulated for this simulation before 51 | * we started the search. (We have simulated them earlier.) */ 52 | int base_playouts; 53 | /* Number of last dynkomi adjustment. */ 54 | int last_dynkomi; 55 | /* Number of last game with progress print. */ 56 | int last_print; 57 | /* Number of simulations to wait before next print. */ 58 | int print_interval; 59 | /* Printed notification about full memory? */ 60 | bool fullmem; 61 | 62 | struct time_stop stop; 63 | struct uct_thread_ctx *ctx; 64 | }; 65 | 66 | int uct_search_games(struct uct_search_state *s); 67 | 68 | void uct_search_start(struct uct *u, struct board *b, enum stone color, struct tree *t, struct time_info *ti, struct uct_search_state *s); 69 | struct uct_thread_ctx *uct_search_stop(void); 70 | 71 | void uct_search_progress(struct uct *u, struct board *b, enum stone color, struct tree *t, struct time_info *ti, struct uct_search_state *s, int i); 72 | 73 | bool uct_search_check_stop(struct uct *u, struct board *b, enum stone color, struct tree *t, struct time_info *ti, struct uct_search_state *s, int i); 74 | 75 | struct tree_node *uct_search_result(struct uct *u, struct board *b, enum stone color, bool pass_all_alive, int played_games, int base_playouts, coord_t *best_coord); 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /jni/pachi/uct/slave.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_UCT_SLAVE_H 2 | #define PACHI_UCT_SLAVE_H 3 | 4 | #include "move.h" 5 | #include "distributed/distributed.h" 6 | 7 | struct board; 8 | struct engine; 9 | struct time_info; 10 | 11 | enum parse_code uct_notify(struct engine *e, struct board *b, int id, char *cmd, char *args, char **reply); 12 | char *uct_genmoves(struct engine *e, struct board *b, struct time_info *ti, enum stone color, 13 | char *args, bool pass_all_alive, void **stats_buf, int *stats_size); 14 | void *uct_htable_alloc(int hbits); 15 | void uct_htable_reset(struct tree *t); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /jni/pachi/uct/uct.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_UCT_UCT_H 2 | #define PACHI_UCT_UCT_H 3 | 4 | #include "engine.h" 5 | #include "move.h" 6 | 7 | struct engine *engine_uct_init(char *arg, struct board *b); 8 | 9 | struct board; 10 | struct time_info; 11 | bool uct_gentbook(struct engine *e, struct board *b, struct time_info *ti, enum stone color); 12 | void uct_dumptbook(struct engine *e, struct board *b, enum stone color); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /jni/pachi/uct/walk.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_UCT_WALK_H 2 | #define PACHI_UCT_WALK_H 3 | 4 | #include "move.h" 5 | 6 | struct tree; 7 | struct uct; 8 | struct board; 9 | 10 | void uct_progress_status(struct uct *u, struct tree *t, enum stone color, int playouts, coord_t *final); 11 | 12 | int uct_playout(struct uct *u, struct board *b, enum stone player_color, struct tree *t); 13 | int uct_playouts(struct uct *u, struct board *b, enum stone color, struct tree *t, struct time_info *ti); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /jni/pachi/util.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_UTIL_H 2 | #define PACHI_UTIL_H 3 | 4 | #include 5 | 6 | /* Portability definitions. */ 7 | 8 | #ifdef _WIN32 9 | #include 10 | 11 | #define sleep(seconds) Sleep((seconds) * 1000) 12 | #define __sync_fetch_and_add(ap, b) InterlockedExchangeAdd((LONG volatile *) (ap), (b)); 13 | #define __sync_fetch_and_sub(ap, b) InterlockedExchangeAdd((LONG volatile *) (ap), -(b)); 14 | 15 | /* MinGW gcc, no function prototype for built-in function stpcpy() */ 16 | char *stpcpy (char *dest, const char *src); 17 | 18 | #include 19 | static inline const char * 20 | strcasestr(const char *haystack, const char *needle) 21 | { 22 | for (const char *p = haystack; *p; p++) { 23 | for (int ni = 0; needle[ni]; ni++) { 24 | if (!p[ni]) 25 | return NULL; 26 | if (toupper(p[ni]) != toupper(needle[ni])) 27 | goto more_hay; 28 | } 29 | return p; 30 | more_hay:; 31 | } 32 | return NULL; 33 | } 34 | #endif 35 | 36 | /* Misc. definitions. */ 37 | 38 | /* Use make DOUBLE=1 in large configurations with counts > 1M 39 | * where 24 bits of floating_t mantissa become insufficient. */ 40 | #ifdef DOUBLE 41 | # define floating_t double 42 | # define PRIfloating "%lf" 43 | #else 44 | # define floating_t float 45 | # define PRIfloating "%f" 46 | #endif 47 | 48 | #define likely(x) __builtin_expect(!!(x), 1) 49 | #define unlikely(x) __builtin_expect((x), 0) 50 | 51 | static inline void * 52 | checked_malloc(size_t size, char *filename, unsigned int line, const char *func) 53 | { 54 | void *p = malloc(size); 55 | if (!p) { 56 | fprintf(stderr, "%s:%u: %s: OUT OF MEMORY malloc(%zu)\n", 57 | filename, line, func, size); 58 | exit(1); 59 | } 60 | return p; 61 | } 62 | 63 | static inline void * 64 | checked_calloc(size_t nmemb, size_t size, char *filename, unsigned int line, const char *func) 65 | { 66 | void *p = calloc(nmemb, size); 67 | if (!p) { 68 | fprintf(stderr, "%s:%u: %s: OUT OF MEMORY calloc(%zu, %zu)\n", 69 | filename, line, func, nmemb, size); 70 | exit(1); 71 | } 72 | return p; 73 | } 74 | 75 | #define malloc2(size) checked_malloc((size), __FILE__, __LINE__, __func__) 76 | #define calloc2(nmemb, size) checked_calloc((nmemb), (size), __FILE__, __LINE__, __func__) 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /jni/pachi/version.h: -------------------------------------------------------------------------------- 1 | #ifndef PACHI_VERSION_H 2 | #define PACHI_VERSION_H 3 | 4 | #define PACHI_VERNUM 10.00 5 | #define PACHI_VERNUMS "10.00" 6 | 7 | /* 00. Wang Zhi 8 | * 01. Sansa Meijin 1612-1623 9 | * 02. Sanetsu 8-Dan 1630-1658 10 | * 03. Doetsu 7-Dan 1658-1677 11 | * 04. Dosaku Meijin 1677-1702 12 | * (h) Doteki 7-Dan (1684-1690) 13 | * (h) Sakugen 7-Dan (1692-1699) 14 | * 05. Dochi Meijin 1702-1727 15 | * 06. Chihaku 6-Dan 1727-1733 16 | * 07. Shuhaku 6-Dan 1733-1741 17 | * 08. Hakugen 6-Dan 1741-1754 18 | * 09. Satsugen Meijin 1754-1788 19 | * 10. Retsugen 8-Dan 1788-1808 20 | * 11. Genjo 8-Dan 1808-1827 21 | * 12. Jowa Meijin 1827-1839 22 | * 13. Josaku 7-Dan 1839-1847 23 | * 14. Shuwa 8-Dan 1847-1873 24 | * (h) Shusaku 7-Dan (1848-1862) 25 | * 15. Shuetsu 6-Dan 1873-1879 26 | * 16. Shugen 4-Dan 1879-1884 27 | * 17. Shuei 7-Dan 1884-1886 28 | * 18. Shuho 8-Dan 1886 29 | * 19. Shuei Meijin 1887-1907 30 | * 20. Shugen 6-Dan 1907-1908 31 | * 21. Shusai Meijin 1908-1940 */ 32 | #define PACHI_VERNAME "Satsugen" 33 | 34 | /* -devel except when tagged. */ 35 | #define PACHI_VERDEV "" 36 | 37 | #define PACHI_VERSION PACHI_VERNUMS " (" PACHI_VERNAME PACHI_VERDEV ")" 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /pachi.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':elygo-lib' --------------------------------------------------------------------------------