Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.javascript Subject: Re: Logic conundrums in check Date: Fri, 18 Sep 2020 12:53:36 +0200 Lines: 61 Message-ID: References: <05dec20a-bc09-49d0-907d-b36b2387ea73o@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net tn3n1D1xIjixElpLZOB1kgThCBK94anJYjzAyeuJFC0iU8hVB7 Cancel-Lock: sha1:uvWRA2/3doVly2aFhk2r/laA4rM= In-Reply-To: <05dec20a-bc09-49d0-907d-b36b2387ea73o@googlegroups.com> Content-Language: en-US Xref: csiph.com comp.lang.javascript:38804 On 17.09.20 12:25, Jonas Thörnvall wrote: > I am a bit baffeled about the complexity of checking for check. > Checking if the opponent make you check is straightforward, it is > just to scan the "occupied/controled tiles" of the opponent piece > just moved. > > Similar to check if the king move into an opponent > "occupied/controled" tile you just do two loops first scan thru kings > possible "normal moves" and the other loop compare possible kingtiles > with the opponents "occupied/controlled" tiles. > > But knowing if you move one of your own pieces to cause your own king > to be checked seem to be a complete different animal. Why? You just execute the move and then check the result. > First you have to find your kings position "tile" i don't keep track > of it. Then it seem i actually have to make a "test move" actually Why don't you keep track on which tile the king is? > moving my own piece to a new position. And then do the above king vs > opponenet controled tiles. > > So to check if your king actually will become checked when you move a > piece seem to be the most computing intensive part of rules? No. This is just, because your data structures seem to lack information. Every piece you move can have a current position and a future position for a proposed move which is not done yet. So you can check with the positions the current status and the status which might be if a move will really be done. > So all your own pieces and their possible moves multiplied by > opponents all pieces and their possible moves compared with your king > position, to see if King is checked? No. You just need to check the current positions and the *single* piece if you want to move it. > Its clearly the most complex thing to program in chess so far. Just because you did not break down the logic yet. As I mentioned a while ago already - there is a complete(!) chess implementation in JavaScript with less than 3 KB total: A working example: Yes - this is a bit brainfuck since the code is extremely optimized. But it really works. -- Arno Welzel https://arnowelzel.de