Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

143 Neutral

About cryo75

  • Rank
  1. cryo75

    Negascout behaves oddly

    What's the best way to fix the odd behaviors? Playing around with the values of the evaluation function?   Also, should the depth of the killer moves be the depth left (like the tt) or the current depth?
  2. cryo75

    Negascout behaves oddly

    I commented out the transposition table code. It is not always playing better. In some games, the AI has a clear win on the next move, however it stays moving other unnecessary pieces. Looks like this happens more often in the endgame.   I use 2 depths because (as you can see from the code above), I do:   1. check if the current depth is the maximum depth (maximum being that of the current iterative of the ID) and if it is, I exit the function, and 2. if current depth == 0, then the search is at the root and I need to save the the move too.   I don't know how I can eliminate one depth variable.
  3. I have a negascout function within an iterative deepening with aspiration windows framework. The negascout function uses move ordering, transposition tables, killer moves and history heuristics. The game is a nine men's morris (yes.. still working on it in my free time!!)   The problem is that over 70% of the time, the AI is not that aggressive, ie. when the AI has a chance to capture pieces, it doesn't.   This is the function: private int negaScout(int curDepth, int maxDepth, int alpha, int beta) { if (curDepth >= maxDepth || board.getWon() != 0) return board.getScore(); //Check if the move is in the TT long key = board.getZobristKey(); TTEntry entry = tt.probe(key, curDepth); if (entry != null) { switch (entry.boundType) { case TTEntry.BOUND_EXACT: return entry.score; case TTEntry.BOUND_ALPHA: alpha = Math.max(alpha, entry.score); break; case TTEntry.BOUND_BETA: beta = Math.min(beta, entry.score); break; } if (alpha >= beta) return entry.score; } int val = 0; int bestScore = -INFINITY; Move bestLocalMove = null; boolean foundPV = false; List<Move> moves = sortMoves(board, curDepth, false); for (int i = 0, n = moves.size(); i < n; i++) { Move move = moves.get(i); //PV has been found if (alpha < bestScore) { alpha = bestScore; foundPV = true; } board.make(move, true); if (foundPV) { //Zero window val = -negaScout(curDepth + 1, maxDepth, -alpha - 1, -alpha); if (val > alpha && val < beta) val = -negaScout(curDepth + 1, maxDepth, -beta, -alpha); } else val = -negaScout(curDepth + 1, maxDepth, -beta, -alpha); board.undo(move, true); //Alpha has improved if (val > bestScore) { bestScore = val; bestLocalMove = move; //Beta cut-off if (bestScore >= beta) break; } } //We have the current best move so far at the root if (curDepth == 0) bestMove = bestLocalMove; //Set TT entry flag byte flag = bestScore <= alpha ? TTEntry.BOUND_BETA : bestScore >= beta ? TTEntry.BOUND_ALPHA : TTEntry.BOUND_EXACT; //Store the move in the TT tt.set(key, curDepth, bestScore, flag, bestLocalMove); if (bestLocalMove != null) { //Add to killer moves killers.add(bestLocalMove, curDepth); //Update history heuristics for non-captures if (bestLocalMove.cellRemove == -1) history[bestLocalMove.player][bestLocalMove.cellFrom + 1][bestLocalMove.cellTo + 1] += 1<<(maxDepth-curDepth); } return bestScore; } This is the transpostion table: public class TranspositionTable { private TTEntry[] tt; public TranspositionTable(int size) { tt = new TTEntry[size]; } public TTEntry probe(long key, int depth) { TTEntry entry = tt[(int)(key % tt.length)]; if (entry != null && entry.depth <= depth) return entry; return null; } public void set(long key, int depth, int val, byte boundType, Move move) { int pos = (int)(key % tt.length); tt[pos] = new TTEntry(key, depth, val, boundType, move); } } As you can see in the transposition table, I always do a replace in the 'set' function. However, when I probe, I get the entry only if the entry's depth is smaller than the depth required. By depth here, I mean that depth from the root node, so the smaller the depth the nearer the entry is to the root move.   Is it possible that I'm probing/setting wrong values or could it be the part of the code when the 'Alpha has improved' comment is?   Thanks, Ivan
  4. cryo75

    Speeding up evaluation function

    I added LMR into my current code. Does this make sense? int LMR_DEPTH = 3; int LMR_MOVENUMBER_MINIMUM = 3 for (int i = 0, n = moves.size(); i < n; i++) { moveCount++; Move move = moves.get(i); //Begin Late Move Reduction search boolean reduced = false; if (movesSearched >= LMR_MOVENUMBER_MINIMUM && depth >= LMR_DEPTH && ply < depth) { depth--; reduced = true; } //End Late Move Reduction search //PV has been found if (alpha < bestScore) { alpha = bestScore; foundPV = true; } //Make the move board.make(move, true); //Search if (foundPV) { //Zero window val = -negaScout(-alpha - 1, -alpha, ply + 1, depth); if (val > alpha && val < beta) val = -negaScout(-beta, -alpha, ply + 1, depth); } //PV search else val = -negaScout(-beta, -alpha, ply + 1, depth); //Begin Late Move Reduction research if (reduced && val >= beta) { depth++; val = -negaScout(-beta, -alpha, ply + 1, depth); } //End Late Move Reduction research //Undo the move board.undo(move); //Cut-offs here... }
  5. cryo75

    Speeding up evaluation function

    My move ordering sorts by: transposition move, capture move, primary killer, secondary killer in descending order. It also adds the history heuristic to each move before sorting. I currently don't implement move reduction. Maybe I should consider this too.   my game consists of a 6x4 board and 8 pieces per player. All pieces are of the same value (ie. no king, queen, etc). And the game is just moving pieces from one square to another. Something similar to checkers.
  6. Hi,   My abstract strategy game AI implements negascout in an iterative deepening framework, using zobrist keys and killer moves. I use bitboard representation for my board.   However, when running a version of the game on Android devices, I can only search to a depth of 4, because starting with 5 the search starts taking more time (depth of 5 takes 3-4 seconds per move).   I would like to at least go to depth 5 so I was thinking if it would make sense to store the score of previous game moves in a sort of table and then quickly access them. If the score is not found, the normal eval function kicks in.   Does this make sense, and more importantly, will it bring performance benefits? Thanks  
  7. What is a good way to weaken an AI's strength when using Negascout?   1. Decrease search depth 2. Apply noise to the evaluation score 3. Reduce the number of generated moves
  8. cryo75

    Iterative Deepening

    The TT should be for the whole game, or you'll forget what you learned in the previous search, which is not a good idea. So you have an assert that fails for reasons you don't quite understand? It sounds like removing it is a horrible idea. I make them for the whole game, but I divide every entry by 4 at the beginning of each search, so old entries that are no longer relevant can decay. If you were to make them local to the current search, I think they would work just fine too.     good answer for question 2!! nah I will need to find out what the problem is and solve it.   for the history table and in the case of nine men morris where you have just placement of pieces, moving, and also placement+capture and move+capture is it wise to have a 4d array in this case or should I have a 2 3d arrays (one for each player).   when sorting the history, i would assume that the moves are sorted based on the array of player whose turn it is at that stage of the search. right?   small question about iterative deepening... I have a time limit of 2s and it goes 7 plies deep but sometimes it goes even 8 or 9 but because the time required to complete the search at that depth is more than 2s, it can take up to 6s to complete. should i also quite searching in negascout by checking outOfTim() in the move loop or is it wise to let it finish the search at that depth?
  9. cryo75

    Iterative Deepening

    I've finally managed to implement ID into the search and it's working.  I have a couple of questions:   1. Killer moves are local to the current search. Should the TT also be local to the current search or should it be for the whole game?   2. I also implemented transposition move in the search (before normal negascout search starts). However an assert is failing on makeMove because the current position doesn't belong to the current player on turn. Should I even bother with an assert there?   3. I would like to implment history heuristics. Are these local to the current search or should they be for the whole game?
  10. cryo75

    Iterative Deepening

    I still have problems with the loop. The 4000-6000 moves searched was because the recursive function was search up to 1 depth. That has been fixed but the AI plays worse than without ID. For example, in some cases it loops for 99 depths but finds nothing.   I tried changing the aspiration delta but it didn't help.   Could it that the best move is placed to the top of the list and the search keeps searching the path?
  11. cryo75

    Iterative Deepening

    Now the next step is to add history heuristics. If I understand correctly, hh is just a table that increments a counter on every beta cut-off. Then in the next call to the recursive function, the generated moves are sorted by the counter value (or weights depending on the move type) for that index. Am I right?   So in the case of the nine men morris game I'm doing, i will have this hh: int[color][posFrom][posTo] hh = new int[2][24][24]   During placement stage, I will only have one position, so when incrementing the hh counter, should I check what kind of move it is?
  12. cryo75

    Iterative Deepening

    Ok changed the code you pointed out. As you can see from the snippet above my version of negascout does depth+1 in the recursive function, so I will never hit 0. But I changed 0 to curDepth (which is the current depth of the loop).   The infinite loop resulted from some inconsistencies with the setting up of variables within the ID loop.   I've run a few tests and I noticed that with ID, the moves search are around 4000-6000 compared to over 200000 when using just negascout without ID. Is it possible that there is such a big cut ?
  13. cryo75

    Iterative Deepening

    This is the updated code:   public Move GetBestMove(IBoard board, int depth) { this.maxTime = 9000; this.maxDepth = 100; int alpha = -INFINITY, beta = INFINITY; int scoreGuess = 0; Move bestMove = null; List<Move> moves = board.getMoves(); long startTime = System.nanoTime(); for (curDepth = 1; curDepth < maxDepth && !outOfTime(); curDepth++) { board.make(moves.get(0), true); alpha = -negascout(board, curDepth - 1, scoreGuess - ASPIRATION_SIZE, scoreGuess + ASPIRATION_SIZE, startTime); board.undo(moves.get(0)); if (alpha <= scoreGuess - ASPIRATION_SIZE || alpha >= scoreGuess + ASPIRATION_SIZE) { board.make(moves.get(0), true); alpha = -negascout(board, curDepth - 1, -INFINITY, +INFINITY, startTime); board.undo(moves.get(0)); } int bestPos = -1; for (int i = 1, n = moves.size(); i < n; i++) { board.make(moves.get(i), true); int val = -negascout(board, curDepth - 1, alpha, beta, startTime); board.undo(moves.get(i)); //Keep best move if (val >= alpha) { alpha = val; bestMove = moves.get(i); bestPos = i; } } //Move the best move to the top of the list if (bestPos != -1) { moves.remove(bestPos); moves.add(0, bestMove); } //Set the current best score scoreGuess = alpha; } //Return the move return bestMove; } After the 17th move and it's the AI's turn again, the search enters an infinite loop.   I can't figure out why, because the code looks good to me. However, the negascout function has the following checks:   This one at the top: //Horizon has been reached if (depth == curDepth) { t = board.getScore(); return t; }   And this one when searching deeper (inside the move loop): t = -negascout(board, depth + 1, -b, -a, startTime); if ((t > a) && (t < beta) && (i > 0) && (depth < curDepth - 1)) t = -negascout(board, depth + 1, -beta, -t, startTime);   Could it be that curDepth is wrong here?
  14. cryo75

    Iterative Deepening

    Ok now I have the main deepening loop and inside it the loop to iterate through the moves. Should the aspiration window check be inside the second loop (moves) or move outside to the main loop?
  15. cryo75

    Improving move ordering

    Ok I think I've got the first 3 so far. I sitll didn't implement history heuristics yet but will do so.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!