Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 11 Jun 2013
Offline Last Active Aug 09 2014 01:12 PM

Topics I've Started

Best way to assert the king is not in check when generating moves in chess

13 December 2013 - 10:40 AM

I am now working on generating moves in chess.  I am writing move generation function for every piece (pawn,knight,bishop...)and i currently generation all possible moves without any kind of filtering.  


 I wonder what is the preffered way to assert that the king is not in check after the move is played (e.g if the move is valid).    The way i see it,  I have to actually play the move on the board and only than can I know that the king is not exposed or attacked.     But should I make this valiadation in the alpha-beta function (in the actual evaluation stage) ?   or maybe "artificialy"  make the move inside the moves generation function and decide if i should add it to the list in the first place.    


Also,  can you give me some tips on how to improve the move generation ?  maybe not generate all possible moves? 



Checking for offboard squares with bitboards (vs padded array)

07 December 2013 - 01:02 PM

I am currently starting to work on a chess engine.

With padded array it is easy to check for offboard squares,  but what if I want to use bitboards to represent the board, how should I make this validation?      should I keep a padded array (along with the bitboards)  for those checks or there are maybe another more effiecient / bitboard oriented solutions ?



Best approach for pattern recognition in Gomoku

28 September 2013 - 02:11 AM

I am working on a little Gomoku engine, this project s mainly for learning and practicing in programming and the C language, and it is also fun smile.png

I want to represent the board with Bit-Boards , so I can do pattern checking for the evalution function and checkWin function etc.   
first thing,  because the board is huge (15x15), I need to hold more than one bit word for each player representing the board.     one idea I got from a forum member here is to have 15  16-bit words for each player,every word represents a row.  the board will look like this:


29   28   27   26   25   24 23 22 21 20 19 18 17 16 15  ....

14   13   12   11   10   9   8   7   6   5   4   3   2   1   0


But here comes my dillema.     let's say I want to check a certain row for a threat pattern that looks like this:   011110 (1E Hex, 30 Dec),  than i will go through every 6 bits in that row (and shift the row >> by 1 in every iteration) and with a & operation check if there is a match.   And I will do this for every threat pattern I want to check. 


So far it sound good, and also pretty fast the way I see it.    But checking the rows is easy becuase I have them ready in bit sets.   but what about the columns and diagonals? (even harder then columns!)   How can check for a bit- pattern match if i don't have the columns and diagonals already in my disposal  (like the rows).  ?     

The way i see it, I can "generate" a new 16 bit word each time I want to check for a certain column/diagonal, by means of starting from an empty number ( unsigned short y = 0) and than construct it one by one (with | operation or +...) by going through the rows at the right indexes.   and than, after i have a ready to go bit-word, i can again do the bit pattern checking to see if i have a threat someplace in that line.   just like i do for the rows.   Hope i am understood smile.png   


But it seems like very ineffiecient and slow way to do this, because imagine that in the evaluation function i will have to do this "construction" operation for every vertical and diagonal line on the board  (unlike the check win function where i can just do this for the last played square!).

So my way to get around this, is to just have the diagonal and columns already in my disposal,(every player with have 15 rows,15 columns,21 left diagonals and another 21 right diagonals)  so actually when i make a move on the board, I will have to play it on the row,columns and both diagonals for the played square (for each player!).     But than i can just go through all the lines and do the pattern checking.  The penalty will be a slightly slower make and unmake move functions ,but the evaluation function and check win functions the operation will be much much faster.  

It seems like a good idea, But i wonder if you maybe can suggest me better approach,  Maybe there is a way to check for patterns on bit boards in a more clever way than this naive way.    

My first considertion is performance ofcourse, so ican search for a deeper depth in less time.  The search space in Gomoku is huge already!


Killer moves heuristic question

09 September 2013 - 06:00 PM

My killer moves implementation is usually consists of 2 killers for each depth.  whenever a new move cause a cut off, i check if it is != from the main killer move, and if it is ,I switch the main and secondary killer and than place the new move instead of the main killer.  

The code is like this: 


void insertKiller(int depth,int killer){
    if(killersTable[depth][0] == -2){     //The killers table is initiated with -2..indicates that no moves yet inserted.   here i check if the main killer move  
        killersTable[depth][0] = killer;    // is occupied, and if not i just insert the move to the first position. 
    else{     // if there is already a move in that certain depth, i check if it is different from the one in the first position, and if it is, i do the switching 
        if(killer != killersTable[depth][0]){
            killersTable[depth][1] = killersTable[depth][0];
            killersTable[depth][0] = killer;
My question is ,when i try to play the second killer in a certain position, and it causes a cut off,  do i need to replace it with the first killer (the main killer)   or should i just keep it placed in it's original position (the second position)  
I hope my question is clear,  my english is not the best :)

Generate moves in Gomoku

05 September 2013 - 08:28 AM

The board in gomoku is very large (15x15), and it takes a lot of time for the computer to think when analyzing the whole board.   Even static ordering of the moves from the middle rows (let's say the inner 9x9 board than expanding out) is not much of the help.    

what is the preferred way to generate the moves so that the space search will be minimized as much as possible, but at the same time, I don't want the engine to underestimate the opponent's threats in the sidelines of the board.    Right now I am searching the whole board and even at depth 5 it is starting to take a long time (with killer moves).