Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #38681
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2020-08-06 09:31 -0700 |
| References | <73e9271a-a86d-4eb6-9927-9c84d60c9cc6o@googlegroups.com> <XnsAC0995916183eejj99@194.109.6.166> |
| Message-ID | <19bd3446-2d76-4e6d-a131-ee4a9834c331o@googlegroups.com> (permalink) |
| Subject | Re: Allowed moves database chessboard, knight to many entries.... |
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
Den onsdag 29 juli 2020 kl. 00:55:42 UTC+2 skrev Evertjan.:
> <jonas.thornvall@gmail.com> wrote on 28 Jul 2020 in comp.lang.javascript:
>
> > Anyone have a good idea how i can ***autogenerate them***
> > in followin format.
>
> Well, not your format, but standard notation:
>
> <script>
>
> const jumps = [[ 1, 2, 2, 1,-1,-2, -2,-1], [-2,-1, 1, 2, 2, 1, -1,-2]];
>
> const knightLegalMoves = (from) => {
> const fromPos = from.split('');
> const result = [];
> for (let i = 0; i < 8; i++ ) {
> knight1Move(fromPos, jumps[0][i], jumps[1][i], result);
> };
> return result;
> }
>
> const knight1Move = (fromPos, letJump, numbJump, result) => {
> const lettVal = fromPos[0].charCodeAt(0) - 65;
> const numbVal = fromPos[1] - 1;
> let letValRes = lettVal + letJump;
> if (letValRes < 0 || letValRes > 7) return;
> let numbValRes = numbVal + numbJump;
> if (numbValRes < 0 || numbValRes > 7) return;
> result.push( String.fromCharCode(letValRes + 65) + (numbValRes + 1) );
> };
>
> console.log( knightLegalMoves('E4') );
> // (8) ["F2", "G3", "G5", "F6", "D6", "C5", "C3", "D2"]
>
> console.log( knightLegalMoves('G1') );
> // (3) ["H3", "F3", "E2"]
>
> console.log( knightLegalMoves('A1') );
> // (2) ["C2", "B3"]
>
> console.log( knightLegalMoves('H8') );
> // (2) ["F7", "G6"]
>
> </script>
>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)
Hello Evertjan i am not sure how the above distinguish the moves inside from the ones outside, i guess it somehow translate positions to rows and columns and i checks is if the new value within range of column and row after you add or subtract values. I decided to go for a dumb lookup table for knights afterall.
I managed rooks, knights and bishops and started with pawns and knights. I guess King is just a queen with single move. The haredest part seem to be to check if the king move into a possision in check. Because it seem one basicly have to scan thru all opponents pieces possible positions.
The standard notation is probably the way to go but a lookup table is never wrong "unless you put wrong values into it".
Thanks for refreshing memory had totally forgot about standard notation.
JT
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Allowed moves database chessboard, knight to many entries.... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-07-28 14:31 -0700
Re: Allowed moves database chessboard, knight to many entries.... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-07-28 14:53 -0700
Re: Allowed moves database chessboard, knight to many entries.... "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-07-29 00:55 +0200
Re: Allowed moves database chessboard, knight to many entries.... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-08-06 09:31 -0700
Re: Allowed moves database chessboard, knight to many entries.... "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-08-06 19:01 +0200
Re: Allowed moves database chessboard, knight to many entries.... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-08-08 04:43 -0700
Re: Allowed moves database chessboard, knight to many entries.... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-08-08 04:53 -0700
Re: Allowed moves database chessboard, knight to many entries.... "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-08-08 14:45 +0200
Re: Allowed moves database chessboard, knight to many entries.... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-08-10 02:11 -0700
Re: Allowed moves database chessboard, knight to many entries.... "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-08-10 12:48 +0200
Re: Allowed moves database chessboard, knight to many entries.... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-08-11 11:24 -0700
Re: Allowed moves database chessboard, knight to many entries.... "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-08-11 23:33 +0200
Re: Allowed moves database chessboard, knight to many entries.... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-08-11 14:40 -0700
Re: Allowed moves database chessboard, knight to many entries.... luserdroog <luser.droog@gmail.com> - 2020-08-11 15:57 -0700
Re: Allowed moves database chessboard, knight to many entries.... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-08-12 00:40 -0700
Re: Allowed moves database chessboard, knight to many entries.... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-08-12 00:42 -0700
Re: Allowed moves database chessboard, knight to many entries.... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-08-12 12:12 +0100
Re: Allowed moves database chessboard, knight to many entries.... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-08-12 05:13 -0700
Re: Allowed moves database chessboard, knight to many entries.... luserdroog <luser.droog@gmail.com> - 2020-08-12 10:23 -0700
Re: Allowed moves database chessboard, knight to many entries.... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-08-12 00:50 -0700
Re: Allowed moves database chessboard, knight to many entries.... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-08-12 01:00 -0700
Re: Allowed moves database chessboard, knight to many entries.... "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-08-12 11:58 +0200
Re: Allowed moves database chessboard, knight to many entries.... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-08-12 05:14 -0700
Re: Allowed moves database chessboard, knight to many entries.... "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-08-08 14:44 +0200
Re: Allowed moves database chessboard, knight to many entries.... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-08-22 08:10 -0700
Re: Allowed moves database chessboard, knight to many entries.... Scott Sauyet <scott@sauyet.com> - 2020-08-25 16:03 -0700
Re: Allowed moves database chessboard, knight to many entries.... Scott Sauyet <scott@sauyet.com> - 2020-08-25 15:06 -0700
csiph-web