Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - romichess

Pages: [1] 2 3 ... 10
1
Programs / Re: Maybe some fun, maybe not
« on: April 12, 2021, 03:43:53 pm »
Sixty frames = one simulated year.

Changed the mechanics a bit. Added more color information.
Green - too young
Grey - too old
Pink - female
Blue - male
Solid Pink - take a guess

Things that affect the outcome.
Population density - the larger the starting population the more likely the simulation will sustain
Size of the circles - the larger they are the more plentiful will be the collisions
CONST min - The lower the more fruitful the society will be
CONST maxm - The higher "
CONST maxf - The higher "

The goal is to achieve simulation sustainability without too explosive growth and with not too many failures.

DISCLAIMER ABOUT THE CURRENT SETTINGS
It is just a numbers game. The settings are restricted to what is commonly possible. They are not 100% realistic. It is not meant to be politically correct. So just consider these settings being for a primitive society without written laws or moral standards.

The morally correct may want to increase the circle size and increase the minimum age! Etc.
Code: QB64: [Select]
  1. TYPE OBJECT
  2.     sex AS INTEGER
  3.     age AS INTEGER
  4.     x AS SINGLE
  5.     y AS SINGLE
  6.     vx AS SINGLE
  7.     vy AS SINGLE
  8.     dt AS INTEGER
  9.  
  10. DIM SHARED object(1000) AS OBJECT
  11.  
  12. CONST min = 750
  13. CONST maxm = 4800
  14. CONST maxf = 2760
  15.  
  16.  
  17.  
  18. SCREEN _NEWIMAGE(sw, sh, 256)
  19.  
  20.  
  21. Initialize
  22.  
  23. repeat = 1
  24.  
  25. WHILE repeat
  26.     CLS
  27.  
  28.     FOR i = 0 TO 999
  29.         IF object(i).age > 6000 THEN
  30.             object(i).sex = 0
  31.             _CONTINUE
  32.         END IF
  33.         IF object(i).sex = 1 AND object(i).age > min AND object(i).age < maxm THEN
  34.             FOR j = 0 TO 999
  35.                 IF object(j).age > 6000 THEN
  36.                     object(j).sex = 0
  37.                     _CONTINUE
  38.                 END IF
  39.                 IF object(j).sex = 2 AND object(j).age > min AND object(j).age < maxf AND object(j).dt = 0 THEN
  40.                     d = SQR((ABS(object(i).x - object(j).x) ^ 2) + (ABS(object(i).y - object(j).y) ^ 2))
  41.                     IF d < 13 THEN object(j).dt = 46
  42.                 END IF
  43.                 IF object(j).dt = 1 THEN
  44.                     object(j).dt = 0
  45.                     twins = RND * 250
  46.                     count = 0
  47.                     IF twins = 1 THEN count = 1
  48.                     FOR l = 0 TO count
  49.                         FOR k = 0 TO 999
  50.                             IF object(k).sex = 0 THEN
  51.                                 object(k).sex = RND * 2 + 1
  52.                                 object(k).age = 0
  53.                                 object(k).x = RND * (sw - 24) + 12
  54.                                 object(k).y = RND * (sh - 24) + 12
  55.                                 object(k).dt = 0
  56.                                 EXIT FOR
  57.                             END IF
  58.                         NEXT
  59.                     NEXT
  60.                 END IF
  61.             NEXT
  62.         END IF
  63.     NEXT
  64.  
  65.     FOR i = 0 TO 999
  66.         IF object(i).sex = 0 THEN _CONTINUE
  67.         object(i).age = object(i).age + 1
  68.         IF object(i).sex = 2 AND object(i).dt > 1 THEN object(i).dt = object(i).dt - 1
  69.         c = 2
  70.         IF object(i).sex = 1 THEN
  71.             IF object(i).age > min THEN c = 11
  72.             IF object(i).age > maxf THEN c = 7
  73.         END IF
  74.         IF object(i).sex = 2 THEN
  75.             IF object(i).age > min THEN c = 13
  76.             IF object(i).age > maxf THEN c = 7
  77.         END IF
  78.         object(i).vx = object(i).vx + RND * .1 - .05
  79.         object(i).vy = object(i).vy + RND * .1 - .05
  80.         object(i).x = object(i).x + object(i).vx
  81.         object(i).y = object(i).y + object(i).vy
  82.         IF object(i).x < 13 THEN object(i).vx = 1
  83.         IF object(i).x > sw - 13 THEN object(i).vx = -1
  84.         IF object(i).y < 13 THEN object(i).vy = 1
  85.         IF object(i).y > sh - 13 THEN object(i).vy = -1
  86.         CIRCLE (object(i).x, object(i).y), 12, c
  87.         IF object(i).sex = 2 AND object(i).dt > 0 THEN PAINT (object(i).x, object(i).y), c
  88.     NEXT
  89.  
  90.     IF INKEY$ = CHR$(27) THEN repeat = 0
  91.  
  92.     _LIMIT 60
  93.  
  94.     _DISPLAY
  95.  
  96.  
  97. SUB Initialize
  98.     FOR i = 0 TO 999
  99.         object(i).sex = 0
  100.     NEXT
  101.     FOR i = 0 TO 100
  102.         object(i).sex = 1
  103.         object(i).age = RND * 6000
  104.         object(i).x = RND * (sw - 24) + 12
  105.         object(i).y = RND * (sh - 24) + 12
  106.  
  107.     NEXT
  108.     FOR j = i + 1 TO i * 2
  109.         object(j).sex = 2
  110.         object(j).age = RND * 6000
  111.         object(j).x = RND * (sw - 24) + 12
  112.         object(j).y = RND * (sh - 24) + 12
  113.     NEXT
  114.  

2
Programs / Maybe some fun, maybe not
« on: April 12, 2021, 06:59:11 am »
I was inspired today to write this silly simulation when I watched Fellippe's pandemic simulation video. It is not about the pandemic. It is about something different. It is not really a true simulation. It is a silly simulation. And hopefully it may also be fun. Some silly fun!
Code: QB64: [Select]
  1. TYPE OBJECT
  2.     sex AS INTEGER
  3.     age AS INTEGER
  4.     x AS SINGLE
  5.     y AS SINGLE
  6.     vx AS SINGLE
  7.     vy AS SINGLE
  8.     dt AS INTEGER
  9.  
  10. DIM SHARED object(1000) AS OBJECT
  11.  
  12.  
  13.  
  14. SCREEN _NEWIMAGE(sw, sh, 256)
  15.  
  16.  
  17. Initialize
  18.  
  19. repeat = 1
  20.  
  21. WHILE repeat
  22.     CLS
  23.  
  24.     FOR i = 0 TO 999
  25.         IF object(i).age > 6000 THEN
  26.             object(i).sex = 0
  27.             _CONTINUE
  28.         END IF
  29.         IF object(i).sex = 1 AND object(i).age > 960 AND object(i).age < 5400 THEN
  30.             FOR j = 0 TO 999
  31.                 IF object(i).age > 6000 THEN
  32.                     object(i).sex = 0
  33.                     _CONTINUE
  34.                 END IF
  35.                 IF object(j).sex = 2 AND object(j).age > 960 AND object(j).age < 2760 THEN
  36.                     d = SQR((ABS(object(i).x - object(j).x) ^ 2) + (ABS(object(i).y - object(j).y) ^ 2))
  37.                     IF d < 13 AND object(j).dt = 0 THEN
  38.                         object(j).dt = 46
  39.                         FOR k = 0 TO 999
  40.                             IF object(k).sex = 0 THEN
  41.                                 object(k).sex = RND * 2 + 1
  42.                                 object(k).age = 0
  43.                                 object(k).x = RND * (sw - 24) + 12
  44.                                 object(k).y = RND * (sh - 24) + 12
  45.                                 EXIT FOR
  46.                             END IF
  47.                         NEXT
  48.                     END IF
  49.                 END IF
  50.             NEXT
  51.         END IF
  52.     NEXT
  53.  
  54.     FOR i = 0 TO 999
  55.         IF object(i).sex = 0 THEN _CONTINUE
  56.         object(i).age = object(i).age + 1
  57.         IF object(i).dt > 0 THEN object(i).dt = object(i).dt - 1
  58.         c = 11
  59.         IF object(i).sex = 2 THEN c = 13
  60.         object(i).vx = object(i).vx + RND * .1 - .05
  61.         object(i).vy = object(i).vy + RND * .1 - .05
  62.         object(i).x = object(i).x + object(i).vx
  63.         object(i).y = object(i).y + object(i).vy
  64.         IF object(i).x < 13 THEN object(i).vx = 1
  65.         IF object(i).x > sw - 13 THEN object(i).vx = -1
  66.         IF object(i).y < 13 THEN object(i).vy = 1
  67.         IF object(i).y > sh - 13 THEN object(i).vy = -1
  68.         CIRCLE (object(i).x, object(i).y), 12, c
  69.         'PAINT (object(i).x, object(i).y), c
  70.     NEXT
  71.  
  72.     IF INKEY$ = CHR$(27) THEN repeat = 0
  73.  
  74.     _LIMIT 60
  75.  
  76.     _DISPLAY
  77.  
  78.  
  79. SUB Initialize
  80.     FOR i = 0 TO 999
  81.         object(i).sex = 0
  82.     NEXT
  83.     FOR i = 0 TO 40
  84.         object(i).sex = 1
  85.         object(i).age = RND * 100
  86.         object(i).x = RND * (sw - 24) + 12
  87.         object(i).y = RND * (sh - 24) + 12
  88.  
  89.     NEXT
  90.     FOR j = i + 1 TO i * 2
  91.         object(j).sex = 2
  92.         object(j).age = RND * 100
  93.         object(j).x = RND * (sw - 24) + 12
  94.         object(j).y = RND * (sh - 24) + 12
  95.     NEXT
  96.  

3
Programs / Re: Chess Programming Tutorial
« on: April 12, 2020, 08:37:08 pm »
When I want to code something in basic like I would in C I have to stop what I am doing, research if basic has an equivalent, understand the syntax, learn the syntax, remember the syntax and then try to make it work. In C I just know how.

For example, when generating a capture en passant move one could simply use an IF statement like so for white:

IF to_square = ep_square then
target_square = to_square - 10 ' on a 12x10 board
ELSE
target_square = to_square
END IF
target = board(target_square)

In C one can do it like above or like this:

target_square = ts ^ ((en_passant_bit == 1 << ts) << 3);
target = board[target_square];

This uses unsigned 64 bit integers. It takes advantage of the fact that bit 4 is set for all the possible en passant squares. It works by computing the truth value of (en_passant_bit == 1 << ts) which yields a 0 or 1. Then it left shifts the 0 or 1 into bit 4 which results in either 0 or 8 that is then exclusive_ored with the 4th bit of the to_square .

This might be able to be done in basic but without doing a lot of work and experiencing much aggravation and spending a lot of time researching I just do not know if it can be.

 
   

4
Programs / Re: Chess Programming Tutorial
« on: April 12, 2020, 07:40:44 pm »
I have not abandoned this project. It is just that I do not think in basic as easily as I think in C. So I have been writing a chess engine in C that I then will translate into basic. It is going wonderfly! And it will not be a traditional engine by any comparison. It might even be paradigm changing! My engine RomiChess was "famous" for its learning algorithm. But that was end of game learning where it stores every game it plays (or imported games) into a learn file with reinforcement learning values. The new engine will learn in real time during a game. Also it will not have a traditional evaluation function. Instead it will collect statistics from the search that it will analyze to select a move to play. Both of the above is why it will be (fingers crossed) a paradigm changer. Wish me luck. :)   

5
QB64 Discussion / Re: Will QB64 produce jump tables from SELECT CASE
« on: March 27, 2020, 02:58:35 am »
If the cases are a sequence of numbers, 0, 1, 2, ...., n, then for the application in question, how large would n be?
Would each case have it's own sub, or would some cases share the same sub?
I am thinking of some sort of binary search could be implemented, rather than linearly starting at 0 and testing for a match with each possible integer up to n.
Steve clued me in on the right alternative in another thread, ON GOTO/GOSUB.

6
Programs / Re: Chess Programming Tutorial
« on: March 26, 2020, 07:38:10 pm »
ON GOSUB is cleaner than ON GOTO. And it is even cleaner than SELECT CASE, switch() or C's jumptables. C makes one create full functions and they are outside of the calling function. Here the code is embedded in the same sub from which they are called. Very nice! And I'm not going to look at main.txt because if I do and QB64 does something jenky then I'll just get upset again, lol. Here is just the structure of the new Generate_Moves sub without the piece code so one can easily see the structure. And I did change the constants to start at 1 rather than 0 so they would work correctly with ON GOSUB.

Code: QB64: [Select]
  1. SUB Generate_Moves
  2.     piece_index = piece(start_index(wtm)).nxt
  3.     DO
  4.         from_square = piece(piece_index).squ
  5.         ON piece(piece_index).typ GOSUB WP, WN, WB, WR, WQ, WC, WK, BP, BN, BB, BR, BQ, BC, BK, TR
  6.         piece_index = piece(piece_index).nxt
  7.     LOOP
  8.     EXIT SUB
  9.     WP:
  10.     ON white_pawns(from_square) GOSUB WX2R, WL2R, WL2X, WX1R, WL1R, WL1X, WXER, WLER, WLEX, WXPR, WLPR, WLPX
  11.     END
  12.  
  13.     WX2R:
  14.  
  15.     END
  16.  
  17.     WL2R:
  18.  
  19.     END
  20.  
  21.     WL2X:
  22.  
  23.     END
  24.  
  25.     WX1R:
  26.  
  27.     END
  28.  
  29.     WL1R:
  30.  
  31.     END
  32.  
  33.     WL1X:
  34.  
  35.     END
  36.  
  37.     WXER:
  38.  
  39.     END
  40.  
  41.     WLER:
  42.  
  43.     END
  44.  
  45.     WLEX:
  46.  
  47.     END
  48.  
  49.     WXPR:
  50.  
  51.     END
  52.  
  53.     WLPR:
  54.  
  55.     END
  56.  
  57.     WLPX:
  58.  
  59.     END
  60.  
  61.     WN:
  62.  
  63.     END
  64.  
  65.     WB:
  66.  
  67.     END
  68.  
  69.     WR:
  70.  
  71.     END
  72.  
  73.     WQ:
  74.  
  75.     END
  76.  
  77.     WC:
  78.  
  79.     END
  80.  
  81.     WK:
  82.  
  83.     END
  84.  
  85.     BP:
  86.     ON black_pawns(from_square) GOSUB BX2R, BL2R, BL2X, BX1R, BL1R, BL1X, BXER, BLER, BLEX, BXPR, BLPR, BLPX
  87.     END
  88.  
  89.     BX2R:
  90.  
  91.     END
  92.  
  93.     BL2R:
  94.  
  95.     END
  96.  
  97.     BL2X:
  98.  
  99.     END
  100.  
  101.     BX1R:
  102.  
  103.     END
  104.  
  105.     BL1R:
  106.  
  107.     END
  108.  
  109.     BL1X:
  110.  
  111.     END
  112.  
  113.     BXER:
  114.  
  115.     END
  116.  
  117.     BLER:
  118.  
  119.     END
  120.  
  121.     BLEX:
  122.  
  123.     END
  124.  
  125.     BXPR:
  126.  
  127.     END
  128.  
  129.     BLPR:
  130.  
  131.     END
  132.  
  133.     BLPX:
  134.  
  135.     END
  136.  
  137.     BN:
  138.  
  139.     END
  140.  
  141.     BB:
  142.  
  143.     END
  144.  
  145.     BR:
  146.  
  147.     END
  148.  
  149.     BQ:
  150.  
  151.     END
  152.  
  153.     BC:
  154.  
  155.     END
  156.  
  157.     BK:
  158.  
  159.     END
  160.  
  161.     TR:
  162.     EXIT SUB
  163.     END
  164.  

7
Programs / Re: Chess Programming Tutorial
« on: March 26, 2020, 05:23:34 pm »
You could get there with 12 IF statements, if you were a complete beginner at data interpretation.  Simply by breaking those statements into binary values, you easily reduce the maximum number of comparisons down to 4.

IF X < 7 THEN '1 TO 6
   IF X < 4 THEN '1 TO 3
      IF X < 3 THEN 'IT'S 1 OR 2
           IF X < 2 THEN 'IT'S 1   ELSE 'IT'S 2
     ELSE 'IT'S 3
     END IF
   ELSE 'IT'S 4 TO 6
        'AS ABOVE
   END IF
ELSE 'IT'S 7 TO 12
     'AS ABOVE
END IF

A maximum of 4 comparisons for up to 16 items...  It's not quite as fast as 1 to 1 jump tables, but it's not bad overall.



Remember, you can always fall back on the old ON... GOTO... statements also.

ON X GOTO 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200

I think those tend to be 1 to 1 jump style lists.
Yes, of course hand crafted If blocks can be optimised. In my code though I'm using SELECT CASE because I just assumed that QB64 would write an equivalent C switch statement. I'm new to QB variant basic. The ON...GOTO statement might be the answer. I'll check it out. Thanks!

8
Programs / Re: Chess Programming Tutorial
« on: March 26, 2020, 04:27:24 pm »
I've played some pretty quick and impressive chess games in GWBASIC back in the day on 8088 hardware. I'm sure QB64 is up to the task. Give it a try.

I appreciate your comment and previous experience, really. My perspective is different. I've been playing in chess tournaments since I was 12yo. The first chess program that could give me any fight at all was Chessmaster 2100 on an 80386 machine. My record against Stockfish the world's strongest pc chess engine is 4 draws and 4 losses for a performance rating of 3100 which is higher than the current world champions rating. But then I know how chess engines work so I can play better against them. Also my record against Stockfish while receiving QN odds and giving SF the first move is two draws and a win. Most grandmasters can not even do that!

Okay, so I need to temper-down my opinion as to what a chess engine needs to be to the people here that might be interested. I can try to do that.

9
Programs / Re: Chess Programming Tutorial
« on: March 26, 2020, 03:11:17 pm »
No problem mixing your languages, of course. But this:

Did you try using the select case block you proposed in the first post of the thread you started about SELECT CASE? Did you actually compile it and run it just to make sure it would work as slow as you expect or are you assuming it will be so slow without trying first?

Move generation, captures only generation, make move and unmake move all benefit greatly from jump tables. There are 12 cases just for the pawn. We can get to the correct pawn code by one jump that is not conditional or we can get there by IF IF IF IF IF IF IF IF IF IF IF IF until we find the correct one. The problem in chess is it is constantly in flux and predicting the outcome of any if statement tends toward 50/50 and false branch predictions drags down performance tremendously. If ones goal was to write a correct but intolerably slow chess engine then it does not matter. But in this tutorial my code does not make sense because it is counter productive to the goal of writing a fast chess engine. If statements are just not good for performance in a chess engine.

10
Programs / Re: Chess Programming Tutorial
« on: March 26, 2020, 03:40:47 am »
Okay, because of Steve we may be back in business. The code in temp/main.txt can be swapped with actual C/C++ source code of my choosing. If that is the case I'll just create my own jump tables. Once I have an index. I'll just insert code like this.

void wpmf(short from_square) {
// white pawn code
}

void wnmf(short from_square) {
// white knight code
}

void wbmf(short from_square) {
// white bishop code
}

void (*movegenf[]) (short) = { wpmf, wnmf, wbmf, ... };

Then to call the correct move gen function all that needs to be written is:

movegen[index](from_square);

I wonder if it will really be that simple?

11
QB64 Discussion / Re: Will QB64 produce jump tables from SELECT CASE
« on: March 26, 2020, 03:15:48 am »
It's BASIC. If constructs from other languages get thrown in then it's not BASIC any longer.

But but but a jump table can be created from a SELECT CASE construct without the basic coder even being aware. There would be absolutely no change to the basic language itself. Sorry if I was unclear about that.

12
Programs / Re: Chess Programming Tutorial
« on: March 26, 2020, 02:19:27 am »
Well I got my answer about the SELECT CASE statement and how QB64 handles it. It just converts SELECT CASE to a series of IF statements. And there is no point continuing this tutorial on blazingly fast chess coding in a language that is incapable of it. It would be illusionary at best and even ((very)much) slower than carefully handcrafted IF statement blocks at worst. What would be the point of continuing? It would be disasterly slow when done. It would be better just to rewrite everything using IF statements and I can't do that, lol. However, the 120 cell board is a valuable idea and doubly linked piece list are a big performance boost especially in an endgame with few pieces left on the board.  My EarlyWork.zip file will demonstrate the power of the programming techniques in this tutorial. Sorry, they are in C and even assembler but there is an exe for each. On my i7-3930k the Godzilla example generates and makes/unmakes 65 million moves per second just using one thread. In 1.86 seconds it traverses from the original starting position all possible moves to 6 moves deep. Carnivor is an actual working chess engine that will run in the windows console. Time per move is set by st 30 for 30 seconds or sd 9 for nine moves deep. Moves are entered like e2e4 or e7e8q for queening or e1g1 for king side castling. Etc. Any Questions? Just ask!

13
QB64 Discussion / Re: Will QB64 produce jump tables from SELECT CASE
« on: March 26, 2020, 12:24:19 am »
You can check the c++ result by opening internal/temp/main.txt after the IDE gives you an OK in the status bar.

And no, the answer is no.

A select case block is a glorified (and very convenient) long IF block.

Thanks for the answer. That is very sad for performance. My chess program is going to run really slow. With a few performance enhancements QB64 could become a serious production language. That is a shame that it is not because I really like the Basic syntax.

14
QB64 Discussion / Will QB64 produce jump tables from SELECT CASE
« on: March 25, 2020, 09:22:10 pm »
What if the code is written like so:
SELECT CASE
    CASE 0
        sub0 par1
    CASE 1
        sub1 par1
    CASE 2
        sub2 par1
    ...
END SELECT
 
Will the C++ compiler produce jump tables?

15
Programs / Re: Chess Programming Tutorial
« on: March 25, 2020, 08:18:32 pm »
Let me try to explain the move generator a little better then. Using lots of IF statements in a chess engine is a performance killer. I avoid IF statements whenever possible. In C there are two choices. A switch (SELECT CASE) statement and an array of function pointers. These days I'd use the function pointers which is called a jump table. C/C++ compilers can make jump tables out of switch statements but it is hit and miss. C/C++ compilers can also substitute IF statement for switch cases if there are not enough cases. That is why I'd use function pointer arrays to take all decisions away from the compiler. As far as I know I do not have that choice in QB64? So all I can do in QB64 is use the theoretically best approach and hope that QB64 and Mingw64 do a good job. With that said let's look at the code.

There is an array of 40 type piece. The piece[0].nxt holds the first white piece and piece[20].nxt holds the first black piece. And start_index(wtm) gives either 0 or 20.
Therefore we get the first piece like so: piece_index = next_piece(start_index(wtm)).
Okay, I see that I changed the data and did not change the code, oops. So make that: 
piece_index = piece(start_index(wtm)).nxt. I'm really sorry about that, too many senior moments. Anyway, now that we have the first piece we can find its from square: from_square = piece(piece_index).squ. When we are done with the piece we get the next piece at the end of the main loop like this: piece_index = piece(piece_index).nxt. And I have not added that yet, another oops. So yes, it would be hard to understand in such an incomplete state, my bad :(. Now that we have the from square, we look up the type of piece it is. Did I mention that on the chessboard are indexes, not piece types. That is why we have to use the piece index to look up its type: SELECT CASE piece(piece_index).typ. The pawns will take more study. Essentially they are treated as 12 different types depending on which square they are on. For example X2R is a white pawn on rank 2 or a black pawn on rank 7 on file 1 and therefore they need not check for a left capture thus the X. A white pawn on rank 2 away from an edge file is L2R. And the 2 means it can move one or two squares. This is all done to avoid a plethora of IF statements. Also, why make checks that can be avoided all at the cost of one SELECT CASE statement. In the pawn cases 2 is double move, 1 is single, E is check for en passant and P is promotion.

The knights are much more simple. The knight moves can be done in a loop executed 8 times. However, it is faster to "unroll the loop" and repeat the code 8 times.

            CASE WN
                to_square = from_square + 8 'one up and two to the left
                target = chess_board(to_square) 'EMPTY, piece_index or off-edge square
                action = white_target(target) 'exactly the action to take
                SELECT CASE action
                    CASE EMPTY_SQUARE
                        Record_Move from_square, to_square
                    CASE FRIENDLY_PIECE
                    CASE ENEMY_PIECE
                        Record_Capture from_square, to_square, target
                    CASE OFF_BOARD
                END SELECT 'on to the next offset

The sliders are more fun! Once again we unroll the outer loop.

            CASE WB
                to_square = from_square + 9 'prime first to square, up and to the left
                DO
                    target = chess_board(to_square) same as for knight
                    action = white_targets(target)
                    SELECT CASE action
                        CASE EMPTY_SQUARE
                            Record_Move from_square, to_square
                            to_square = to_square + 9 'This time we are in a do loop, next t_s
                        CASE FRIENDLY_PIECE
                            EXIT DO 'we exit the loop when we can't go further
                        CASE ENEMY_PIECE
                            Record_Capture from_square, to_square, target
                            EXIT DO
                        CASE OFF_BOARD
                            EXIT DO
                    END SELECT
                LOOP

More will become clear. For example the various record move subs will not return right away. They will call the capture only search to resolve captures and add a score to each move. This must be done at the leafs of the tree anyway and doing it for every move in the tree cost very little and has huge benefits. The first is that in the gen all moves routine there is no ENEMY_KING case because only legal moves are generated as the capture search will catch any illegal move and not record it. And having a score for move ordering is huge because the alpha-beta routine performs more spectacularly the better the move ordering is. The end result is that there will be a legal (as opposed to pseudo legal) list of moves that we can do a one pass sort to find the move with the best score to try first. And if it is the best move a huge amount of the search tree will be beta pruned.

I hope this helps. :))

 

Pages: [1] 2 3 ... 10