Android Open Source - android-chess Search Algorithm Runner






From Project

Back to project page android-chess.

License

The source code is released under:

MIT License

If you think the Android project android-chess listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package jwtc.chess.algorithm;
//from  ww w  .ja  va  2  s.  com
import jwtc.chess.GameControl;
import jwtc.chess.JNI;
import jwtc.chess.Move;

public class SearchAlgorithmRunner implements Runnable{
  protected GameControl m_control;
  public SearchAlgorithmRunner(GameControl gc){
    m_control = gc;
  }
    // @Override
    public void run() {
      try
    {
        JNI _jni = m_control.getJNI();
        if(_jni.isEnded() != 0)
          return;
      
      m_control.disableControl();
      
      if(m_control.getLevelMode() == GameControl.LEVEL_PLY){
        
        int level = m_control.getLevelPly();
        _jni.searchDepth(level); 
        int move = _jni.getMove();
        m_control.sendMoveMessageFromThread(move);
        
        int evalCnt = _jni.getEvalCount();
        String s;
        
        if(evalCnt == 0){
          s = "From opening book";
        }
        else {
          s = "Searched at " + level + " ply";
        }
        m_control.sendMessageFromThread(s);
        
      } else {
        
        int level = m_control.getLevel();
        int secs[] = {1, 1, 2, 4, 8, 10, 20, 30, 60, 300, 900, 1800}; // 1 offset, so 3 extra 1 unused secs
        //////////////////////////////////////////////////////////////////////
        // start search thread
        _jni.searchMove(secs[level]);
        
        long lMillies = System.currentTimeMillis();
        int move, tmpMove, value, ply = 1, evalCnt, j, iSleep = 1000, iNps; String s; float fValue;
        while(_jni.peekSearchDone() == 0){
          //m_control.sendMessageFromThread("SearchAlg - peeking");
          //Log.i("SearchAlgorithmRunner", "sleep");
          Thread.sleep(iSleep);
          
          //Log.i("SearchAlgorithmRunner", "peeking");
          ply = _jni.peekSearchDepth();
          
          value = _jni.peekSearchBestValue();
          evalCnt = _jni.getEvalCount();
          fValue = (float)value / 100.0F;
           
          s = "";
          
          if(ply > 5){
            ply = 5;
          }
          for(j = 0; j < ply; j++){
            tmpMove = _jni.peekSearchBestMove(j);
            if(tmpMove != 0)
              s += Move.toDbgString(tmpMove).replace("[", "").replace("]", "") + " ";
          }
          if(ply == 5){
            s += "...";
          }
          
          s = s + "\n\t" + String.format("%.2f", fValue) /*+ "\t@ " + ply*/;
          
          m_control.sendMessageFromThread(s);
        }
        
        move = _jni.getMove();
        //Log.i("SearchAlgorithmRunner", "sending move message");
        m_control.sendMoveMessageFromThread(move);
        
        value = _jni.peekSearchBestValue();
        fValue = (float)value / 100.0F;
        evalCnt = _jni.getEvalCount();
        
        if(evalCnt == 0){
          s = "From opening book";
        } else {
          //s = "";
          int iTime = (int)((System.currentTimeMillis()-lMillies)/1000); 
          iNps = (int)(evalCnt / iTime);
          s = iNps + " N/s (" + iTime + " s)" + "\n\t" + String.format("%.2f", fValue);
        }
        m_control.sendMessageFromThread(s);
        
      } // else to level = 1
      ///////////////////////////////////////////////////////////////////////
    }
    catch(Exception ex)
    {
      //m_control.setMessage(ex.toString());
      //co.pl(ex);
      ex.printStackTrace(System.out);
    }
    }
}




Java Source Code List

jwtc.android.chess.ChessFieldView.java
jwtc.android.chess.ChessImageView.java
jwtc.android.chess.ChessPreferences.java
jwtc.android.chess.ChessViewBase.java
jwtc.android.chess.ChessView.java
jwtc.android.chess.GamesListView.java
jwtc.android.chess.HtmlActivity.java
jwtc.android.chess.ImageCacheObject.java
jwtc.android.chess.MyBaseActivity.java
jwtc.android.chess.MyPGNProvider.java
jwtc.android.chess.PGNView.java
jwtc.android.chess.SaveGameDlg.java
jwtc.android.chess.UI.java
jwtc.android.chess.convergence.Connection.java
jwtc.android.chess.convergence.ConvergenceActivity.java
jwtc.android.chess.convergence.RestServer.java
jwtc.android.chess.iconifiedlist.IconifiedTextListAdapter.java
jwtc.android.chess.iconifiedlist.IconifiedTextView.java
jwtc.android.chess.iconifiedlist.IconifiedText.java
jwtc.android.chess.ics.CustomCommands.java
jwtc.android.chess.ics.ICSChatDlg.java
jwtc.android.chess.ics.ICSChessView.java
jwtc.android.chess.ics.ICSClient.java
jwtc.android.chess.ics.ICSConfirmDlg.java
jwtc.android.chess.ics.ICSMatchDlg.java
jwtc.android.chess.ics.TelnetSocket.java
jwtc.android.chess.ics.TimesealInputStream.java
jwtc.android.chess.ics.TimesealOutputStream.java
jwtc.android.chess.ics.TimesealPipe.java
jwtc.android.chess.ics.TimesealingSocket.java
jwtc.android.chess.puzzle.ChessViewPractice.java
jwtc.android.chess.puzzle.ChessViewPuzzle.java
jwtc.android.chess.puzzle.MyPuzzleProvider.java
jwtc.android.chess.puzzle.practice.java
jwtc.android.chess.puzzle.puzzle.java
jwtc.android.chess.tools.FileListView.java
jwtc.android.chess.tools.PGNProcessor.java
jwtc.android.chess.tools.importactivity.java
jwtc.android.chess.tools.pgntool.java
jwtc.android.chess.main.java
jwtc.android.chess.options.java
jwtc.android.chess.setup.java
jwtc.android.chess.start.java
jwtc.android.timeseal.TimesealingSocket.java
jwtc.android.timeseal.streams.a.java
jwtc.android.timeseal.streams.b.java
jwtc.android.timeseal.streams.c.java
jwtc.chess.ChessPuzzleProvider.java
jwtc.chess.GameControl.java
jwtc.chess.JNI.java
jwtc.chess.Move.java
jwtc.chess.PGNColumns.java
jwtc.chess.PGNEntry.java
jwtc.chess.PGNProvider.java
jwtc.chess.Pos.java
jwtc.chess.Valuation.java
jwtc.chess.algorithm.SearchAlgorithmRunner.java
jwtc.chess.algorithm.UCIWrapper.java
jwtc.chess.board.BoardConstants.java
jwtc.chess.board.BoardHashKeys.java
jwtc.chess.board.BoardMembers.java
jwtc.chess.board.BoardStatics.java
jwtc.chess.board.ChessBoard.java