| 1 | /*************************************************************************** |
| 2 | qgtp.h - description |
| 3 | ------------------- |
| 4 | begin : Thu Nov 29 2001 |
| 5 | copyright : (C) 2001 by PALM Thomas , DINTILHAC Florian, HIVERT Anthony, PIOC Sebastien |
| 6 | email : |
| 7 | ***************************************************************************/ |
| 8 | |
| 9 | /*************************************************************************** |
| 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or modify * |
| 12 | * it under the terms of the GNU General Public License as published by * |
| 13 | * the Free Software Foundation; either version 2 of the License, or * |
| 14 | * (at your option) any later version. * |
| 15 | * * |
| 16 | ***************************************************************************/ |
| 17 | |
| 18 | #ifndef QGTP_H |
| 19 | #define QGTP_H |
| 20 | |
| 21 | #include <QProcess> |
| 22 | #include <QList> |
| 23 | |
| 24 | #define IGTP_BUFSIZE 2048 /* Size of the response buffer */ |
| 25 | #define OK 0 |
| 26 | #define FAIL -1 |
| 27 | |
| 28 | |
| 29 | /** |
| 30 | *@author PALM Thomas , DINTILHAC Florian, HIVERT Anthony, PIOC Sebastien |
| 31 | */ |
| 32 | |
| 33 | struct Point |
| 34 | { |
| 35 | Point(char _x, char _y) : x(_x), y(_y) {} |
| 36 | char x,y; |
| 37 | }; |
| 38 | |
| 39 | class QGtp : public QObject{ |
| 40 | Q_OBJECT |
| 41 | |
| 42 | signals: |
| 43 | void signal_computerPlayed( int, int ); |
| 44 | void computerResigned(); |
| 45 | void computerPassed(); |
| 46 | |
| 47 | public: |
| 48 | void slot_readFromStdout(); |
| 49 | void slot_processExited(int , QProcess::ExitStatus ); |
| 50 | |
| 51 | QGtp(); |
| 52 | ~QGtp(); |
| 53 | |
| 54 | bool isBusy() { return busy; } |
| 55 | |
| 56 | /**************************** |
| 57 | * * |
| 58 | ****************************/ |
| 59 | QString getLastMessage(); |
| 60 | int openGtpSession(QString path, QString args, int size, float komi, int handicap); |
| 61 | QProcess * programProcess ; |
| 62 | void fflush(QByteArray s); |
| 63 | |
| 64 | /**************************** |
| 65 | * Administrative commands. * |
| 66 | ****************************/ |
| 67 | int quit (); |
| 68 | |
| 69 | /**************************** |
| 70 | * Program identity. * |
| 71 | ****************************/ |
| 72 | int name (); |
| 73 | int protocolVersion (); |
| 74 | int version (); |
| 75 | |
| 76 | /*************************** |
| 77 | * Setting the board size. * |
| 78 | ***************************/ |
| 79 | int setBoardsize (int size); |
| 80 | int queryBoardsize(); |
| 81 | |
| 82 | /*************************** |
| 83 | * Clearing the board. * |
| 84 | ***************************/ |
| 85 | int clearBoard (); |
| 86 | |
| 87 | /************ |
| 88 | * Setting. * |
| 89 | ************/ |
| 90 | int setKomi (float k); |
| 91 | int setLevel (int level); |
| 92 | |
| 93 | /****************** |
| 94 | * Playing moves. * |
| 95 | ******************/ |
| 96 | int playblack (int x, int y); |
| 97 | int playblackPass (); |
| 98 | int playwhite (int x, int y); |
| 99 | int playwhitePass (); |
| 100 | int fixedHandicap (int handicap); |
| 101 | int set_free_handicap (QList<Point> handicap_stones); |
| 102 | int loadsgf (QString filename,int movNumber=0,char c='A',int i=0); |
| 103 | |
| 104 | /***************** |
| 105 | * Board status. * |
| 106 | *****************/ |
| 107 | int whatColor (char c, int j); |
| 108 | int countlib (char c, int j); |
| 109 | int findlib (char c, int j); |
| 110 | int isLegal (QString color, char c, int j); |
| 111 | int allLegal (QString color); |
| 112 | int captures (QString color); |
| 113 | |
| 114 | /********************** |
| 115 | * Retractable moves. * |
| 116 | **********************/ |
| 117 | int trymove (QString color, char c, int j); |
| 118 | int popgo (); |
| 119 | |
| 120 | /********************* |
| 121 | * Tactical reading. * |
| 122 | *********************/ |
| 123 | int attack (char c, int j); |
| 124 | int defend (char c, int j); |
| 125 | int increaseDepths (); |
| 126 | int decreaseDepths (); |
| 127 | |
| 128 | /****************** |
| 129 | * owl reading. * |
| 130 | ******************/ |
| 131 | int owlAttack (char c, int j); |
| 132 | int owlDefend (char c, int j); |
| 133 | |
| 134 | /******** |
| 135 | * eyes * |
| 136 | ********/ |
| 137 | int evalEye (char c, int j); |
| 138 | |
| 139 | /***************** |
| 140 | * dragon status * |
| 141 | *****************/ |
| 142 | int dragonStatus (char c, int j); |
| 143 | int sameDragon (char c1, int i1, char c2, int i2); |
| 144 | int dragonData (); |
| 145 | int dragonData (char c, int i); |
| 146 | |
| 147 | /*********************** |
| 148 | * combination attacks * |
| 149 | ***********************/ |
| 150 | int combinationAttack (QString color); |
| 151 | |
| 152 | /******************** |
| 153 | * generating moves * |
| 154 | ********************/ |
| 155 | int genmoveBlack (); |
| 156 | int genmoveWhite (); |
| 157 | int genmove (QString color,int seed=0); |
| 158 | int topMovesBlack (); |
| 159 | int topMovesWhite (); |
| 160 | int undo (int i=1); |
| 161 | int finalStatus (char c, int i, int seed=0); |
| 162 | int finalStatusList (QString status, int seed=0); |
| 163 | |
| 164 | /************** |
| 165 | * score * |
| 166 | **************/ |
| 167 | int finalScore (int seed=0); |
| 168 | int estimateScore (); |
| 169 | int newScore (); |
| 170 | |
| 171 | /************** |
| 172 | * statistics * |
| 173 | **************/ |
| 174 | int getLifeNodeCounter (); |
| 175 | int getOwlNodeCounter (); |
| 176 | int getReadingNodeCounter (); |
| 177 | int getTrymoveCounter (); |
| 178 | int resetLifeNodeCounter (); |
| 179 | int resetOwlNodeCounter (); |
| 180 | int resetReadingNodeCounter (); |
| 181 | int resetTrymoveCounter (); |
| 182 | |
| 183 | /********* |
| 184 | * debug * |
| 185 | *********/ |
| 186 | int showboard (); |
| 187 | int dumpStack (); |
| 188 | int debugInfluence (QString color, QString list); |
| 189 | int debugMoveInfluence (QString color, char c, int i, QString list); |
| 190 | int influence (QString color); |
| 191 | int moveInfluence (QString color, char c, int i); |
| 192 | int wormCutstone (char c, int i); |
| 193 | int wormData (); |
| 194 | int wormData (char c, int i); |
| 195 | int wormStones (); |
| 196 | int tuneMoveOrdering (int MOVE_ORDERING_PARAMETERS); |
| 197 | int echo (QString param); |
| 198 | int help (); |
| 199 | int reportUncertainty (QString s); |
| 200 | int shell(QString s); |
| 201 | int knownCommand(QString s); |
| 202 | |
| 203 | private : |
| 204 | QByteArray encodeCoors(int x, int y); |
| 205 | QByteArray intToQByteArray(int i); |
| 206 | |
| 207 | int _cpt; /* Number of the request */ |
| 208 | char *_outFile; |
| 209 | char *outFile; |
| 210 | FILE *_inFile; |
| 211 | QString _response, answer; |
| 212 | QList<int> moveRequests; |
| 213 | |
| 214 | int waitResponse(); |
| 215 | |
| 216 | bool responseReceived,issueCmdNb ; |
| 217 | |
| 218 | bool busy; |
| 219 | }; |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | #endif |