Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #38618 > unrolled thread

Allowed moves database chessboard, knight to many entries....

Started byJonas Thörnvall <jonas.thornvall@gmail.com>
First post2020-07-28 14:31 -0700
Last post2020-08-25 15:06 -0700
Articles 20 on this page of 27 — 5 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

Page 1 of 2  [1] 2  Next page →


#38618 — Allowed moves database chessboard, knight to many entries....

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-07-28 14:31 -0700
SubjectAllowed moves database chessboard, knight to many entries....
Message-ID<73e9271a-a86d-4eb6-9927-9c84d60c9cc6o@googlegroups.com>
I have covered all moves except for the knight, i do not look forward to it, it is basicly 64 positions that can take on from 4-8 new positions.

My ooard is basicly an array ranging from 0-63.

I would like each knight position and its new potential positions be registered as a single element. So basicly 64 elements with 4 to 8 positoins?

64*8 is the reason for not do it manually. Because it will take some days.
Of course just layout 3+2 or 2+3 from position. But for some reason i just got the idea the moves should be in a lookup array.


Anyone have a good idea how i can ***autogenerate them*** in followin format.
function moveDB(){
//horisontal.push("A1,B1,C1,D1,E1,F1,G1,H1","A2,B2,C2,D2,E2,F2,G2,H2","A3,B3,C3,D3,E3,F3,G3,H3","A4,B4,C4,D4,E4,F4,G4,H4","A5,B5,C5,D5,E5,F5,G5,H5","A6,B6,C6,D6,E6,F6,G6,H6","A7,B7,C7,D7,E7,F7,G7,H7","A8,B8,C8,D8,E8,F8,G8,H8");
//vertical.push("A1,A2,A3,A4,A5,A6,A7,A8","B1,B2,B3,B4,B5,B6,B7,B8","C1,C2,C3,C4,C5,C6,C7,C8","D1,D2,D3,D4,D5,D6,D7,D8","E1,E2,E3,E4,E5,E6,E7,E8","F1,F2,F3,F4,F5,F6,F7,F8","G1,G2,G3,G4,G5,G6,G7,G8","H1,H2,H3,H4,H5,H6,H7,H8");

//Above is just for example before i realised it is easier use the index.


horisontal.push("0,1,2,3,4,5,6,7","8,9,10,11,12,13,14,15","16,17,18,19,20,21,22,23","24,25,26,27,28,29,30,31","32,33,34,35,36,37,38,39","40,41,42,43,44,45,46,47","48,49,50,51,52,53,54,55","56,57,58,59,60,61,62,63");
vertical.push("0,8,16,24,32,40,48,56","1,9,17,25,33,41,49,57","2,10,18,26,34,42,50,58","3,11,19,27,35,43,51,59","4,12,20,28,36,44,52,60","5,13,21,29,37,45,53,61","6,14,22,30,38,46,54,62","7,15,23,31,39,47,55,63");
diagonalRight.push("0,9,18,27,36,45,54,63","8,17,26,35,44,53,62","16,25,34,43,52,61","24,33,42,51,60","32,41,50,59","40,49,58","48,57","1,10,19,28,37,46,55","2,11,20,29,38,47","3,12,21,30,39","4,13,22,31","5,14,23","6,15");
diagonalLeft.push("7,14,21,28,35,42,49,54","15,22,29,36,43,50,57","23,30,37,44,51,58","31,38,45,52,59","39,46,53,60","47,54,61","55,62","6,13,20,27,34,41,48","5,12,19,26,33,40","4,11,18,25,32","3,10,17,24","2,9,16","1,8");


}

[toc] | [next] | [standalone]


#38619

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-07-28 14:53 -0700
Message-ID<695fd590-8eac-481a-b28c-4f41c1266413o@googlegroups.com>
In reply to#38618
Den tisdag 28 juli 2020 kl. 23:31:22 UTC+2 skrev Jonas Thörnvall:
> I have covered all moves except for the knight, i do not look forward to it, it is basicly 64 positions that can take on from 4-8 new positions.
> 
> My ooard is basicly an array ranging from 0-63.
> 
> I would like each knight position and its new potential positions be registered as a single element. So basicly 64 elements with 4 to 8 positoins?
> 
> 64*8 is the reason for not do it manually. Because it will take some days.
> Of course just layout 3+2 or 2+3 from position. But for some reason i just got the idea the moves should be in a lookup array.
> 
> 
> Anyone have a good idea how i can ***autogenerate them*** in followin format.
> function moveDB(){
> //horisontal.push("A1,B1,C1,D1,E1,F1,G1,H1","A2,B2,C2,D2,E2,F2,G2,H2","A3,B3,C3,D3,E3,F3,G3,H3","A4,B4,C4,D4,E4,F4,G4,H4","A5,B5,C5,D5,E5,F5,G5,H5","A6,B6,C6,D6,E6,F6,G6,H6","A7,B7,C7,D7,E7,F7,G7,H7","A8,B8,C8,D8,E8,F8,G8,H8");
> //vertical.push("A1,A2,A3,A4,A5,A6,A7,A8","B1,B2,B3,B4,B5,B6,B7,B8","C1,C2,C3,C4,C5,C6,C7,C8","D1,D2,D3,D4,D5,D6,D7,D8","E1,E2,E3,E4,E5,E6,E7,E8","F1,F2,F3,F4,F5,F6,F7,F8","G1,G2,G3,G4,G5,G6,G7,G8","H1,H2,H3,H4,H5,H6,H7,H8");
> 
> //Above is just for example before i realised it is easier use the index.
> 
> 
> horisontal.push("0,1,2,3,4,5,6,7","8,9,10,11,12,13,14,15","16,17,18,19,20,21,22,23","24,25,26,27,28,29,30,31","32,33,34,35,36,37,38,39","40,41,42,43,44,45,46,47","48,49,50,51,52,53,54,55","56,57,58,59,60,61,62,63");
> vertical.push("0,8,16,24,32,40,48,56","1,9,17,25,33,41,49,57","2,10,18,26,34,42,50,58","3,11,19,27,35,43,51,59","4,12,20,28,36,44,52,60","5,13,21,29,37,45,53,61","6,14,22,30,38,46,54,62","7,15,23,31,39,47,55,63");
> diagonalRight.push("0,9,18,27,36,45,54,63","8,17,26,35,44,53,62","16,25,34,43,52,61","24,33,42,51,60","32,41,50,59","40,49,58","48,57","1,10,19,28,37,46,55","2,11,20,29,38,47","3,12,21,30,39","4,13,22,31","5,14,23","6,15");
> diagonalLeft.push("7,14,21,28,35,42,49,54","15,22,29,36,43,50,57","23,30,37,44,51,58","31,38,45,52,59","39,46,53,60","47,54,61","55,62","6,13,20,27,34,41,48","5,12,19,26,33,40","4,11,18,25,32","3,10,17,24","2,9,16","1,8");
> 
> 
> }

I am not even sure a lookup table is the way to go, i mean horisontal and vertical is just a matter of adding and multiplying, diagonals lines is just the difference of 7 to the right 9 to the left so is the above for nothing or does a table give any benefits? 

[toc] | [prev] | [next] | [standalone]


#38620

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2020-07-29 00:55 +0200
Message-ID<XnsAC0995916183eejj99@194.109.6.166>
In reply to#38618
<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)

[toc] | [prev] | [next] | [standalone]


#38681

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-08-06 09:31 -0700
Message-ID<19bd3446-2d76-4e6d-a131-ee4a9834c331o@googlegroups.com>
In reply to#38620
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 
 

[toc] | [prev] | [next] | [standalone]


#38682

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2020-08-06 19:01 +0200
Message-ID<XnsAC11C18F2E942eejj99@194.109.6.166>
In reply to#38681
=?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 06
Aug 2020 in comp.lang.javascript: 

> 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.

No need for that. 
The resulting rows and columns must have a "primitive number" between 0 and 
7 inclusieve. Otherwise they are outside the board. My code checks for that.

> 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". 

I would uge you to use "primitive numbering" with 0 to 7 inside all 
routines, and have a standard conversion routine to and from "standard 
notation".
 
> Thanks for refreshing memory had totally forgot about standard notation.



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#38700

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-08-08 04:43 -0700
Message-ID<0965b2e8-47ec-42b7-a294-a874d5f176abo@googlegroups.com>
In reply to#38682
Den torsdag 6 augusti 2020 kl. 19:02:19 UTC+2 skrev Evertjan.:
> =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 06
> Aug 2020 in comp.lang.javascript: 
> 
> > 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.
> 
> No need for that. 
> The resulting rows and columns must have a "primitive number" between 0 and 
> 7 inclusieve. Otherwise they are outside the board. My code checks for that.
> 
> > 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". 
> 
> I would uge you to use "primitive numbering" with 0 to 7 inside all 
> routines, and have a standard conversion routine to and from "standard 
> notation".
>  
> > Thanks for refreshing memory had totally forgot about standard notation.
> 
> 
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Hello Evertjan, i hope it is okay to ask a question not directly about javascript but chess notation.

Is there a general konsensus over protocol/standard used when chess programs communicate with eachother over internet to the gameserver. And is it the same standard as used to store chess games?

I guess something like 
F2 F4
G8 F6
Is sufficient to forward gameplay.

But probably when storing you want to be albe to see both COLOR and PIECE at each position, so probably?

W PF2 F4
B NG8 F6

Is it forwarded as ASCII notation, to server and recepient at other end?
I also want to write the most simplistic server possible for clients/players just a nick and then you can click/challenge other nicks not "in play".

I think i have written chatservers type things in Perl and probably could, i also done a little PHP once. C++, Visual basic seem to much overhead to learn.

If you just want a server that forward ascii messages in cleartext between clients what is the most easy language implement it in?

I've seen there is small perl servers, with basicly just some dozen of rows of code that i probably could adapt. 

I do not think i could run Perl code or PHP at github? So i guess i have to put up a server with DDNS of my own and i can't imagine having a windows machine up and running 24/7 so i have bought a cheap android box that seem to have sufficient power to handle the clients.

Any advice?

[toc] | [prev] | [next] | [standalone]


#38701

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-08-08 04:53 -0700
Message-ID<42350bec-28d0-4b85-89db-1aed763e1026o@googlegroups.com>
In reply to#38700
Den lördag 8 augusti 2020 kl. 13:43:41 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 6 augusti 2020 kl. 19:02:19 UTC+2 skrev Evertjan.:
> > =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 06
> > Aug 2020 in comp.lang.javascript: 
> > 
> > > 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.
> > 
> > No need for that. 
> > The resulting rows and columns must have a "primitive number" between 0 and 
> > 7 inclusieve. Otherwise they are outside the board. My code checks for that.
> > 
> > > 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". 
> > 
> > I would uge you to use "primitive numbering" with 0 to 7 inside all 
> > routines, and have a standard conversion routine to and from "standard 
> > notation".
> >  
> > > Thanks for refreshing memory had totally forgot about standard notation.
> > 
> > 
> > 
> > -- 
> > Evertjan.
> > The Netherlands.
> > (Please change the x'es to dots in my emailaddress)
> 
> Hello Evertjan, i hope it is okay to ask a question not directly about javascript but chess notation.
> 
> Is there a general konsensus over protocol/standard used when chess programs communicate with eachother over internet to the gameserver. And is it the same standard as used to store chess games?
> 
> I guess something like 
> F2 F4
> G8 F6
> Is sufficient to forward gameplay.
> 
> But probably when storing you want to be albe to see both COLOR and PIECE at each position, so probably?
> 
> W PF2 F4
> B NG8 F6
> 
> Is it forwarded as ASCII notation, to server and recepient at other end?
> I also want to write the most simplistic server possible for clients/players just a nick and then you can click/challenge other nicks not "in play".
> 
> I think i have written chatservers type things in Perl and probably could, i also done a little PHP once. C++, Visual basic seem to much overhead to learn.
> 
> If you just want a server that forward ascii messages in cleartext between clients what is the most easy language implement it in?
> 
> I've seen there is small perl servers, with basicly just some dozen of rows of code that i probably could adapt. 
> 
> I do not think i could run Perl code or PHP at github? So i guess i have to put up a server with DDNS of my own and i can't imagine having a windows machine up and running 24/7 so i have bought a cheap android box that seem to have sufficient power to handle the clients.
> 
> Any advice?

Is there any reason that the server should handle any of the game logic, it seem like a waste of resources if many client attached?

[toc] | [prev] | [next] | [standalone]


#38703

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2020-08-08 14:45 +0200
Message-ID<XnsAC1396146B2C1eejj99@194.109.6.166>
In reply to#38701
=?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 08
Aug 2020 in comp.lang.javascript: 

> Is there any reason that the server should handle any of the game logic,
> it seem like a waste of resources if many client attached? 

Ofcource, you are the programmer, you supply your reasons.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#38704

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-08-10 02:11 -0700
Message-ID<b5f52c14-ed6e-4b0a-852d-dca3393d5889o@googlegroups.com>
In reply to#38703
Den lördag 8 augusti 2020 kl. 14:45:49 UTC+2 skrev Evertjan.:
> =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 08
> Aug 2020 in comp.lang.javascript: 
> 
> > Is there any reason that the server should handle any of the game logic,
> > it seem like a waste of resources if many client attached? 
> 
> Ofcource, you are the programmer, you supply your reasons.
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

I beleive there is just king movement, check and rockad left todo, There is some glitch rendering out possible movement forgetting tile that previously rendered. But the logic doing the move seem correct.

Try it out, if not for my programming skills for my artistic rendition ;)
https://jonasth.github.io/chess/chess.html

[toc] | [prev] | [next] | [standalone]


#38705

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2020-08-10 12:48 +0200
Message-ID<XnsAC1582524E3CAeejj99@194.109.6.166>
In reply to#38704
=?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 10 Aug 
2020 in comp.lang.javascript:

> Try it out, if not for my programming skills for my artistic rendition ;)
> https://jonasth.github.io/chess/chess.html

Artistic okay!

Programmatic, 
you are doing multiple testing, 3 times here, where there is no need, 
example:

function random(){
	holder = Math.random() < 0.5;
	if (holder==true){uplayer="white";} 
    else if (holder==false){uplayer="black";}
}

Why not:

function random(){
	holder = Math.random() < 0.5;
	if (holder)
       uplayer = 'white'
    else 
       uplayer = 'black';
};

Or even more consize:

function random(){
	uplayer = (Math.random() < 0.5)
    ? 'white'
    : 'black';
};

or:

function getRandom(){
	return (Math.random() < 0.5)
    ? 'white'
    : 'black';
};

getRandom() = getRandom();

========

However, I would prefer to use a binary global value:

let uplayerIsWhite = true; // default
...
uplayerIsWhite = Math.random() < 0.5;



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#38707

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-08-11 11:24 -0700
Message-ID<39f38e8f-f303-4f76-9034-dc51bf49f7d6o@googlegroups.com>
In reply to#38705
Den måndag 10 augusti 2020 kl. 12:48:46 UTC+2 skrev Evertjan.:
> =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 10 Aug 
> 2020 in comp.lang.javascript:
> 
> > Try it out, if not for my programming skills for my artistic rendition ;)
> > https://jonasth.github.io/chess/chess.html
> 
> Artistic okay!
> 
> Programmatic, 
> you are doing multiple testing, 3 times here, where there is no need, 
> example:
> 
> function random(){
> 	holder = Math.random() < 0.5;
> 	if (holder==true){uplayer="white";} 
>     else if (holder==false){uplayer="black";}
> }
> 
> Why not:
> 
> function random(){
> 	holder = Math.random() < 0.5;
> 	if (holder)
>        uplayer = 'white'
>     else 
>        uplayer = 'black';
> };
> 
> Or even more consize:
> 
> function random(){
> 	uplayer = (Math.random() < 0.5)
>     ? 'white'
>     : 'black';
> };
> 
> or:
> 
> function getRandom(){
> 	return (Math.random() < 0.5)
>     ? 'white'
>     : 'black';
> };
> 
> getRandom() = getRandom();
> 
> ========
> 
> However, I would prefer to use a binary global value:
> 
> let uplayerIsWhite = true; // default
> ...
> uplayerIsWhite = Math.random() < 0.5;
> 
> 
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Honestly Evertjan i find 
Math.random() < 0.5
giving a boolean weird enough, i see no reason to support the confusion of javascript syntax.

[toc] | [prev] | [next] | [standalone]


#38708

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2020-08-11 23:33 +0200
Message-ID<XnsAC16EFA465EBFeejj99@194.109.6.166>
In reply to#38707
<jonas.thornvall@gmail.com> wrote on 11 Aug 2020 in comp.lang.javascript:

> Honestly Evertjan i find 
> Math.random() < 0.5
> giving a boolean weird enough

The result of any comparison must be a boolean.

Programming needs some honest brain exercise.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#38709

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-08-11 14:40 -0700
Message-ID<7c025bee-868d-4182-8a4f-e52c6524659fo@googlegroups.com>
In reply to#38708
Den tisdag 11 augusti 2020 kl. 23:33:36 UTC+2 skrev Evertjan.:
> <jonas.thornvall@gmail.com> wrote on 11 Aug 2020 in comp.lang.javascript:
> 
> > Honestly Evertjan i find 
> > Math.random() < 0.5
> > giving a boolean weird enough
> 
> The result of any comparison must be a boolean.
> 
> Programming needs some honest brain exercise.
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Nah when you look at it first thought it is an assignment a range, Math.randon() less then 0.5

It is just confusing, but you "real" programmers are so inbreeded you never notice LoL

[toc] | [prev] | [next] | [standalone]


#38710

Fromluserdroog <luser.droog@gmail.com>
Date2020-08-11 15:57 -0700
Message-ID<c097e9ab-72d6-4cc2-9198-722d4635c449o@googlegroups.com>
In reply to#38708
On Tuesday, August 11, 2020 at 4:33:36 PM UTC-5, Evertjan. wrote:
> <jonas.thornvall@gmail.com> wrote on 11 Aug 2020 in comp.lang.javascript:
> 
> > Honestly Evertjan i find 
> > Math.random() < 0.5
> > giving a boolean weird enough
> 
> The result of any comparison must be a boolean.
> 
> Programming needs some honest brain exercise.
> 

Without going too far out on a limb, I support the use of relational
operators to produce boolean values. (I also like implicit conversion
from 0 and 1.)

[toc] | [prev] | [next] | [standalone]


#38711

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-08-12 00:40 -0700
Message-ID<c24429d5-85ff-434c-aa10-728dea2d6283o@googlegroups.com>
In reply to#38710
Den onsdag 12 augusti 2020 kl. 00:57:32 UTC+2 skrev luserdroog:
> On Tuesday, August 11, 2020 at 4:33:36 PM UTC-5, Evertjan. wrote:
> > <jonas.thornvall@gmail.com> wrote on 11 Aug 2020 in comp.lang.javascript:
> > 
> > > Honestly Evertjan i find 
> > > Math.random() < 0.5
> > > giving a boolean weird enough
> > 
> > The result of any comparison must be a boolean.
> > 
> > Programming needs some honest brain exercise.
> > 
> 
> Without going too far out on a limb, I support the use of relational
> operators to produce boolean values. (I also like implicit conversion
> from 0 and 1.)

if (Math.random<0.5) {holder=false;}

[toc] | [prev] | [next] | [standalone]


#38712

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-08-12 00:42 -0700
Message-ID<5eec68a9-bbe9-48d9-895c-91cc335b9439o@googlegroups.com>
In reply to#38711
Den onsdag 12 augusti 2020 kl. 09:40:48 UTC+2 skrev Jonas Thörnvall:
> Den onsdag 12 augusti 2020 kl. 00:57:32 UTC+2 skrev luserdroog:
> > On Tuesday, August 11, 2020 at 4:33:36 PM UTC-5, Evertjan. wrote:
> > > <jonas.thornvall@gmail.com> wrote on 11 Aug 2020 in comp.lang.javascript:
> > > 
> > > > Honestly Evertjan i find 
> > > > Math.random() < 0.5
> > > > giving a boolean weird enough
> > > 
> > > The result of any comparison must be a boolean.
> > > 
> > > Programming needs some honest brain exercise.
> > > 
> > 
> > Without going too far out on a limb, I support the use of relational
> > operators to produce boolean values. (I also like implicit conversion
> > from 0 and 1.)
> 
> if (Math.random<0.5) {holder=false;}

Not holder=Math.random<0.5 
It is both syntactical and semantical gibberish

[toc] | [prev] | [next] | [standalone]


#38716

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2020-08-12 12:12 +0100
Message-ID<87h7t886e5.fsf@bsb.me.uk>
In reply to#38712
Jonas Thörnvall <jonas.thornvall@gmail.com> writes:

> Den onsdag 12 augusti 2020 kl. 09:40:48 UTC+2 skrev Jonas Thörnvall:
>> Den onsdag 12 augusti 2020 kl. 00:57:32 UTC+2 skrev luserdroog:
>> > On Tuesday, August 11, 2020 at 4:33:36 PM UTC-5, Evertjan. wrote:
>> > > <jonas.thornvall@gmail.com> wrote on 11 Aug 2020 in comp.lang.javascript:
>> > > 
>> > > > Honestly Evertjan i find 
>> > > > Math.random() < 0.5
>> > > > giving a boolean weird enough
>> > > 
>> > > The result of any comparison must be a boolean.
>> > > 
>> > > Programming needs some honest brain exercise.
>> > > 
>> > 
>> > Without going too far out on a limb, I support the use of relational
>> > operators to produce boolean values. (I also like implicit conversion
>> > from 0 and 1.)
>> 
>> if (Math.random<0.5) {holder=false;}

(you meant to call the function: if (Math.random()<0.5) {holder=false;}

> Not holder=Math.random<0.5 
> It is both syntactical and semantical gibberish

Your code is not equivalent to assignment you dislike.  You'd need
something like

 if (Math.random()<0.5) holder=false; else holder=true;

But what do you think the "Math.random() < 0.5" in the "if" is if not an
expression yielding a true/false result?  And if that is what it is, why
not allow the result to be assigned just like the result of any pther
expression?

Many decades ago, before we knew how to do this stuff, there were
programming languages that only allowed relations and comparisons in
certain positions (the test of an "if" or a "while" etc.) but thankfully
those days are long gone.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#38717

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-08-12 05:13 -0700
Message-ID<e8959083-7f27-4cfd-99c7-217998132ec7o@googlegroups.com>
In reply to#38716
Den onsdag 12 augusti 2020 kl. 13:12:41 UTC+2 skrev Ben Bacarisse:
> Jonas Thörnvall <jonas.thornvall@gmail.com> writes:
> 
> > Den onsdag 12 augusti 2020 kl. 09:40:48 UTC+2 skrev Jonas Thörnvall:
> >> Den onsdag 12 augusti 2020 kl. 00:57:32 UTC+2 skrev luserdroog:
> >> > On Tuesday, August 11, 2020 at 4:33:36 PM UTC-5, Evertjan. wrote:
> >> > > <jonas.thornvall@gmail.com> wrote on 11 Aug 2020 in comp.lang.javascript:
> >> > > 
> >> > > > Honestly Evertjan i find 
> >> > > > Math.random() < 0.5
> >> > > > giving a boolean weird enough
> >> > > 
> >> > > The result of any comparison must be a boolean.
> >> > > 
> >> > > Programming needs some honest brain exercise.
> >> > > 
> >> > 
> >> > Without going too far out on a limb, I support the use of relational
> >> > operators to produce boolean values. (I also like implicit conversion
> >> > from 0 and 1.)
> >> 
> >> if (Math.random<0.5) {holder=false;}
> 
> (you meant to call the function: if (Math.random()<0.5) {holder=false;}
> 
> > Not holder=Math.random<0.5 
> > It is both syntactical and semantical gibberish
> 
> Your code is not equivalent to assignment you dislike.  You'd need
> something like
> 
>  if (Math.random()<0.5) holder=false; else holder=true;
> 
> But what do you think the "Math.random() < 0.5" in the "if" is if not an
> expression yielding a true/false result?  And if that is what it is, why
> not allow the result to be assigned just like the result of any pther
> expression?
> 
> Many decades ago, before we knew how to do this stuff, there were
> programming languages that only allowed relations and comparisons in
> certain positions (the test of an "if" or a "while" etc.) but thankfully
> those days are long gone.
> 
> -- 
> Ben.

That is what i did Ben i even considered skippin the undefined case like Evertjan above.

I just say that things like.

z=A==func();
z=A<func();
z=A>func();

Really hard to read out, for me it is not clear that the assignment to left is a boolean, it more looks like A is less,bigger,equal to result of function.

It is probably just a thing to get used to, but i can't say it comes natural to me.

Do you think the interpretation of above is clear and that it gives a boolean result/assignment?

[toc] | [prev] | [next] | [standalone]


#38719

Fromluserdroog <luser.droog@gmail.com>
Date2020-08-12 10:23 -0700
Message-ID<7bc33b29-dfe8-4bea-bc74-8810e290d7b4o@googlegroups.com>
In reply to#38711
On Wednesday, August 12, 2020 at 2:40:48 AM UTC-5, Jonas Thörnvall wrote:
> Den onsdag 12 augusti 2020 kl. 00:57:32 UTC+2 skrev luserdroog:
> > On Tuesday, August 11, 2020 at 4:33:36 PM UTC-5, Evertjan. wrote:
> > > <jonas.thornvall@gmail.com> wrote on 11 Aug 2020 in comp.lang.javascript:
> > > 
> > > > Honestly Evertjan i find 
> > > > Math.random() < 0.5
> > > > giving a boolean weird enough
> > > 
> > > The result of any comparison must be a boolean.
> > > 
> > > Programming needs some honest brain exercise.
> > > 
> > 
> > Without going too far out on a limb, I support the use of relational
> > operators to produce boolean values. (I also like implicit conversion
> > from 0 and 1.)
> 
> if (Math.random<0.5) {holder=false;}

How about this?

  function random_bool(){
    return Math.random < 0.5;
  }

  holder = random_bool();

I can sympathize with wanting the code to be easily readable.
Here (and often) I think wrapping the tricky part in a function
is a good way to aid readability.

[toc] | [prev] | [next] | [standalone]


#38713

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-08-12 00:50 -0700
Message-ID<454daae0-8dd1-427d-933a-8c3edfe9c4d9o@googlegroups.com>
In reply to#38710
Den onsdag 12 augusti 2020 kl. 00:57:32 UTC+2 skrev luserdroog:
> On Tuesday, August 11, 2020 at 4:33:36 PM UTC-5, Evertjan. wrote:
> > <jonas.thornvall@gmail.com> wrote on 11 Aug 2020 in comp.lang.javascript:
> > 
> > > Honestly Evertjan i find 
> > > Math.random() < 0.5
> > > giving a boolean weird enough
> > 
> > The result of any comparison must be a boolean.
> > 
> > Programming needs some honest brain exercise.
> > 
> 
> Without going too far out on a limb, I support the use of relational
> operators to produce boolean values. (I also like implicit conversion
> from 0 and 1.)

I don't think it is readable, and that was a point with higher order languages.
Especially the last case just weird.
A=1;
B=1;

holder=A<B;
alert(holder);
holder=A>B;
alert(holder);
holder=A==B;
alert(holder);

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.javascript


csiph-web