Board makeBestMove(Board b, int player) { int i, max = -1000, tscore, bestMove = -1; for ( i = 0; i < 64; i++ ) { if ( moveIsLegal(b, i, player) ) { tscore = scoreMove(b, i, player); if ( tscore > max ) { max = tscore; bestMove = i; } } } if ( bestMove > -1 ) { b = makeMove(b, bestMove, player); } return b; }
static void handlePossibleMove(int row, int col, wordRef wordToPlay, direction dirToMove) { // adjust row, col: they are anchor co-ords // D("handling: (%d,%d) word = \"%s\" dir = %d\n",row,col,wordToPlay,dirToMove); if(isLegalMove(me, row, col, wordToPlay, dirToMove)) { int score = scoreMove(me, row, col, wordToPlay, dirToMove); if(score > bestScore) { bestRow = row; bestCol = col; bestScore = score; strncpy(bestWord, wordToPlay, BOARD_SIZE); bestDir = dirToMove; } } }