[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Nqueens Code



This is what I received.  It seems to have cut off a great deal
of info.

Larry Latour

On Fri, 11 Oct 1996, Urbano wrote:

> 
> 
> here goes the code for the nqueens 
> 
> 
> 
> globals [clock]
> to setup
>  ca
>  draw-board
>  crt 1 seth 90
>  setc green
>  setclock 0
> nd
> 
> to draw-board
>  if ( (xcor >= 0) and (xcor <= queens - 1) and  
>       (ycor = 1) )
>     or
>     ( (ycor <= 1) and (ycor >= (-1 * queens)) and  
>       (xcor = -1) )
>     [setpc blue]
>  if (xcor >= 0) and (xcor <= queens - 1) and  
>     (ycor = (-1 * queens) ) 
>     [setpc blue + 2]
>  if (ycor <= +1) and (ycor >= (-1 * queens)) and  
>       (xcor = queens) 
>     [setpc blue + 1] 
> nd
> 
> to tick
>  if num-queens < queens [setclock clock + 1]
> nd
> 
> to attack :val
>  stamp pc + :val
>  ifelse heading = 180 [fd 1]
>    [ifelse heading = 135 [setxy (xcor + 1)  (ycor - 1)]
>                          [setxy (xcor - 1)  (ycor - 1)]]
> nd
> to inc-attack
>  attack 2
> nd
> to dec-attack
>  attack -2
> nd
> to reds
>  if color = red
>     [ifelse (pc = blue)  or 
>             (pc = blue + 1) or 
>             (pc = blue + 2)
>        [die]
>        [inc-attack]]
> nd
> to reds+1
>  if color = red + 1
>     [ifel!
> se (pc = blue)  or 
>             (
>