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


Groups > comp.lang.javascript > #38804

Re: Logic conundrums in check

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Arno Welzel <usenet@arnowelzel.de>
Newsgroups comp.lang.javascript
Subject Re: Logic conundrums in check
Date Fri, 18 Sep 2020 12:53:36 +0200
Lines 61
Message-ID <hsjhtgF7jajU1@mid.individual.net> (permalink)
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

Show key headers only | View raw


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:

<https://nanochess.org/chess4.html>

A working example:

<https://nanochess.org/archive/toledo_javascript_chess_3.html>

Yes - this is a bit brainfuck since the code is extremely optimized. But
it really works.


-- 
Arno Welzel
https://arnowelzel.de

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Logic conundrums in check Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-17 03:25 -0700
  Re: Logic conundrums in check Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-17 03:28 -0700
  Re: Logic conundrums in check John G Harris <niam@jghnorth.org.uk.invalid> - 2020-09-17 14:09 +0100
    Re: Logic conundrums in check Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-17 07:25 -0700
      Re: Logic conundrums in check Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-17 23:50 -0700
    Re: Logic conundrums in check Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-17 07:32 -0700
    Re: Logic conundrums in check Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-17 07:54 -0700
    Re: Logic conundrums in check Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-09-17 21:19 +0100
      Re: Logic conundrums in check Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-17 13:57 -0700
  Re: Logic conundrums in check Arno Welzel <usenet@arnowelzel.de> - 2020-09-18 12:53 +0200
    Re: Logic conundrums in check Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-18 04:48 -0700
      Re: Logic conundrums in check Arno Welzel <usenet@arnowelzel.de> - 2020-09-19 15:17 +0200
        Re: Logic conundrums in check Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-19 07:58 -0700
          Re: Logic conundrums in check Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-19 08:02 -0700
          Re: Logic conundrums in check Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-19 08:05 -0700
          Re: Logic conundrums in check luserdroog <luser.droog@gmail.com> - 2020-09-19 11:27 -0700
            Re: Logic conundrums in check Arno Welzel <usenet@arnowelzel.de> - 2020-09-20 00:10 +0200
              Re: Logic conundrums in check Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-19 16:09 -0700
              Re: Logic conundrums in check luserdroog <luser.droog@gmail.com> - 2020-09-19 17:07 -0700
          Re: Logic conundrums in check Arno Welzel <usenet@arnowelzel.de> - 2020-09-20 00:08 +0200
  Re: Logic conundrums in check Scott Sauyet <scott@sauyet.com> - 2020-09-22 09:55 -0700
    Re: Logic conundrums in check Scott Sauyet <scott@sauyet.com> - 2020-09-22 10:01 -0700
      Re: Logic conundrums in check Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-23 02:26 -0700
        Re: Logic conundrums in check Scott Sauyet <scott.sauyet@gmail.com> - 2020-09-24 19:41 -0700
          Re: Logic conundrums in check Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-24 22:45 -0700
          Re: Logic conundrums in check Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-24 22:58 -0700

csiph-web