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: Sat, 19 Sep 2020 15:17:40 +0200 Lines: 28 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 IGbnBeXvE0Jw6ViffM8yVQlMiZ9m3uNkczfEZOWHS7gvbHpclq Cancel-Lock: sha1:R1jfMo+nLOKAFAjcUB4EC8jGFYY= In-Reply-To: Xref: csiph.com comp.lang.javascript:38808 Jonas Thörnvall: > Den fredag 18 september 2020 kl. 12:53:47 UTC+2 skrev Arno Welzel: >> On 17.09.20 12:25, Jonas Thörnvall wrote: [...] >>> 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? > > Of course its position recorded, but i made tiles an array object and > pieces only properties of the tiles. "Of course i could have a > variable named KingPosition, Queenposition and so on" I would have done this the other way: every tile has the position as property. As there is a maximum of 32 pieces, checking their positions to decide wether a move is possible or not or if the king is in check would not take that long - just check position of the maximum of 31 other pieces and for the "check" test the fields they can move to. BTW: You should also learn how to use a *real* newsserver with a NNTP-client instead of Google Groups. -- Arno Welzel https://arnowelzel.de