Author Topic: Re: midnight chess (work in progress)  (Read 1426 times)

0 Members and 1 Guest are viewing this topic.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: midnight chess (work in progress)
« Reply #15 on: January 29, 2020, 05:34:15 am »
These data statements define most moves.   The format is up/down/left/right, and the
numbers indicate the number of squares that can be moved.  Castling and en passant
have to be handled special.  Pretty simple, eh?

DATA R,8000,0800,0080,0008,0000,0000,0000,0000
DATA N,2010,2001,0210,0201,1020,1002,0120,0102
DATA B,8080,8008,0880,0808,0000,0000,0000,0000
DATA Q,8000,0800,0080,0008,8080,8008,0880,0808
DATA K,1000,0100,0010,0001,1010,1001,0110,0101
DATA P,1000,1001,1010,0000,0000,0000,0000,0000
It works better if you plug it in.

Offline romichess

  • Forum Regular
  • Posts: 145
    • View Profile
Re: midnight chess (work in progress)
« Reply #16 on: January 29, 2020, 03:34:39 pm »
These data statements define most moves.   The format is up/down/left/right, and the
numbers indicate the number of squares that can be moved.  Castling and en passant
have to be handled special.  Pretty simple, eh?

DATA R,8000,0800,0080,0008,0000,0000,0000,0000
DATA N,2010,2001,0210,0201,1020,1002,0120,0102
DATA B,8080,8008,0880,0808,0000,0000,0000,0000
DATA Q,8000,0800,0080,0008,8080,8008,0880,0808
DATA K,1000,0100,0010,0001,1010,1001,0110,0101
DATA P,1000,1001,1010,0000,0000,0000,0000,0000

I can't make sense of those numbers. There is no piece that can move 8 squares in one direction.
My name is Michael, but you can call me Mike :)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: midnight chess (work in progress)
« Reply #17 on: January 29, 2020, 06:04:08 pm »
I can't make sense of those numbers. There is no piece that can move 8 squares in one direction.

I would guess 8 means “unlimited” in that direction.  What I’m curious about, if these represent max movement, is how a knight works.

DATA 0201 would be a max of 2 down, 1 right, but how dose it know it it *has* to be 2/1??  If the figures represent max movement, why can’t the knight move 1 down 0 right, or 0 down, 1 right?  Those figures are within the “max” movement range.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: midnight chess (work in progress)
« Reply #18 on: January 30, 2020, 01:05:27 am »
Duh.  Indeed, I should be using 7, not 8 for unlimited.  Make it a tad faster!

Indeed, the knight is a special case, handled in this snippet:

Code: QB64: [Select]
  1.     mp = b(fr, fc) '                                                 moving piece
  2.     mc = -(mp > 6) - (mp = 0) * 2 '                                  moving color
  3.     mp = mp + (mp > 6) * 6 '                                         white is 1 2 3 4 5 6, black 7 8 9 10 11 12
  4.     IF mc = 1 THEN s = -1 ELSE s = 1 '                               direction a pawn moves
  5.  
  6.     FOR n = 0 TO 7 '                                                 possible 8 dirs
  7.         udlr$ = mp$(mp, n) '                                         up/down/left/right
  8.         IF udlr$ = "0000" THEN EXIT FOR
  9.         du = VAL(MID$(udlr$, 1, 1)) '                                direction up
  10.         dd = VAL(MID$(udlr$, 2, 1)) '                                direction down
  11.         dl = VAL(MID$(udlr$, 3, 1)) '                                direction left
  12.         dr = VAL(MID$(udlr$, 4, 1)) '                                direction right
  13.         IF mp <> Knight THEN '                                       not knight
  14.             du = SGN(du) * s '                                       one square at a time
  15.             dd = SGN(dd) * s
  16.             dl = SGN(dl) * s
  17.             dr = SGN(dr) * s
  18.         END IF
  19.         IF INSTR(udlr$, "8") THEN TrySq = 8 ELSE TrySq = 1
  20.  
It works better if you plug it in.