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


Groups > comp.lang.forth > #46220 > unrolled thread

Rosetta: Generate Chess960 starting position

Started by"WJ" <w_a_x_man@yahoo.com>
First post2016-03-26 21:43 +0000
Last post2016-03-26 21:03 -0700
Articles 3 — 3 participants

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


Contents

  Rosetta: Generate Chess960 starting position "WJ" <w_a_x_man@yahoo.com> - 2016-03-26 21:43 +0000
    Re: Rosetta: Generate Chess960 starting position Paul Rubin <no.email@nospam.invalid> - 2016-03-26 16:11 -0700
      Re: Rosetta: Generate Chess960 starting position hughaguilar96@gmail.com - 2016-03-26 21:03 -0700

#46220 — Rosetta: Generate Chess960 starting position

From"WJ" <w_a_x_man@yahoo.com>
Date2016-03-26 21:43 +0000
SubjectRosetta: Generate Chess960 starting position
Message-ID<nd6vpc$59k$1@dont-email.me>
the bishops must be placed on opposite color squares (i.e.
they must be an odd number of spaces apart or there must be an
even number of spaces between them)

the King must be between two rooks (with any number of other
pieces between them all)

OCaml:

let set_diff a b = List.filter (fun x -> not (List.mem x b)) a ;;

let remaining used = set_diff [0;1;2;3;4;5;6;7] used ;;

let position = Bytes.make 8 ' ' ;;
let table = Hashtbl.create 2000 ;;
for k = 1 to 6 do
  for r1 = 0 to k - 1 do
    for r2 = k + 1 to 7 do
      for b1 = 0 to 6 do
        if not (List.mem b1 [k;r1;r2]) then
          for b2 = b1 + 1 to 7 do
            if not (List.mem b2 [k;r1;r2]) && ((b2-b1) land 1) = 1 then
              List.iter
                (fun q ->
                  let used = [k;r1;r2;b1;b2;q] in
                    List.iter2 (fun i p -> Bytes.set position i p)
                      (used @ remaining used)
                      ['k';'r';'r';'b';'b';'q';'n';'n'] ;
                    Hashtbl.replace table (Bytes.copy position) true)
                (remaining [k;r1;r2;b1;b2])
          done
      done
    done
  done
done ;;

let array = Array.of_list (List.rev
  (Hashtbl.fold (fun k v acc -> k::acc) table []));;
let size = Array.length array in
Printf.printf "There are %d positions.\n" size ;
print_endline "Here are a few:\n" ;
Array.iter print_endline (Array.sub array 0 5);
print_endline " ...";
Array.iter print_endline (Array.sub array (size - 5) 5);
Printf.printf "\nThe traditional position is found at index %d.\n"
  (let rec loop i = if array.(i) = "rnbqkbnr" then i else loop (i+1)
   in loop 0) ;;


There are 960 positions.
Here are a few:

rkbrnbnq
bqnrnkrb
rkrbnqbn
bbqnnrkr
rnqbbkrn
 ...
nbnqrkbr
nnbrkbqr
nqrbbnkr
nnrqbbkr
rnknrqbb

The traditional position is found at index 505.



Will anybody do this in ANS Forth?


-- 
[A]n unholy alliance of leftists, capitalists, and Zionist supremacists has
schemed to promote immigration and miscegenation with the deliberate aim of
breeding us out of existence in our own homelands....  [T]he real aim stays the
same: the biggest genocide in human history....  --- Nick Griffin
(https://www.youtube.com/watch?v=K0hD7IffTJs)

[toc] | [next] | [standalone]


#46223

FromPaul Rubin <no.email@nospam.invalid>
Date2016-03-26 16:11 -0700
Message-ID<87a8lk7s37.fsf@nightsong.com>
In reply to#46220
> the bishops must be placed on opposite color squares

WJ has apparently given up on Euler problems after seeing that they take
actual effort to solve, and his O'Cobol programs kept getting beaten by
Forth programs.

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


#46227

Fromhughaguilar96@gmail.com
Date2016-03-26 21:03 -0700
Message-ID<5414a349-02f3-4c82-8482-d1edcb42c219@googlegroups.com>
In reply to#46223
On Saturday, March 26, 2016 at 4:11:10 PM UTC-7, Paul Rubin wrote:
> > the bishops must be placed on opposite color squares
> 
> WJ has apparently given up on Euler problems after seeing that they take
> actual effort to solve, and his O'Cobol programs kept getting beaten by
> Forth programs.

I don't think that it is cool to put down O'Caml (calling it O'Cobol) just because WJ is promoting it (that is guilt by association). In the past, WJ promoted Gauche Scheme on comp.lang.lisp and here, but he quit doing that. He has also promoted oForth here but Francke told him to quit. These are all good languages --- WJ is a jerk though --- I just tag his posts as spam because none of this has anything to do with Forth.

[toc] | [prev] | [standalone]


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


csiph-web