Jay Campbell on Thu, 1 May 2008 16:16:23 -0700 (MST)


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

[s-d] Play Without Work


I whipped up a little chess tracker in NetLogo, random example output here:

http://jaycampbell.com/nomic/chessview.png

I can expand this (e.g. track real owner) and make it listen to the 
mailing list for specific commands.

Then we could vote in additions like Hose's trontrails.

Here's the source so far if anybody wants a peek. It's enough to help me 
run the MoP till I throw a some regexp in front of it to parse 
plain(ish) English.

=========

globals [ commander flipper ]
turtles-own [ health team owner piece-type ]

to setup
  clear-all
  set commander "Nobody" ;; by default
  paint-chess-board
end

to test
  setup
  set commander "jayc"
  join
  repeat 20 [ purchase ]
end

to purchase
  let new-piece-type item random 20 [ "pawn"  "pawn" "pawn" "pawn" 
"pawn" "pawn" "pawn" "pawn" "pawn" "pawn"
                        "rook" "rook" "rook" "knight" "knight" "knight" 
"bishop" "bishop" "bishop" "queen" ]   
  create-turtles 1 [ awaken new-piece-type ]
end

to awaken [new-piece-type]
  set owner commander
  set piece-type new-piece-type
  set health 100
  set color random 160
  set shape (word "chess " piece-type)
  set size 0.7
  set label who
 
  ifelse piece-type = "king"
    [find-safe-patch]
    [find-safe-patch]
end

to join
  ifelse any? turtles with [piece-type = "king" and owner = commander]
     [ print "This commander already has a King object" ]
     [ create-turtles 1 [ awaken "king" ]]
end

to find-safe-patch
   let counter 0
   let target 0
   let candidate 0
  
   while [ counter < 100 ]
     [
       set counter counter + 1
       set candidate patch random-pxcor random-pycor
       if count turtles-on candidate = 0
         [ set target candidate
           set counter 100 ]
     ]
  
   ifelse is-patch? candidate
     [ move-to candidate ]
     [ print "Unable to place piece after 100 tries." ]
end

to paint-chess-board
  let x 0 let y 0 set flipper false
  while [ x <= 20 ] [ set y 0
    while [ y <= 20 ] [
      ask patch x y [
         ifelse flipper [ set pcolor gray set flipper false ]
                        [ set pcolor white set flipper true ]
      ] set y y + 1
    ] set x x + 1
  ]
end

_______________________________________________
spoon-discuss mailing list
spoon-discuss@xxxxxxxxx
http://lists.ellipsis.cx/mailman/listinfo/spoon-discuss