lights-out
Model was written in NetLogo 6.1.1
•
Viewed 127 times
•
Downloaded 23 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
globals [lights counter mouse-clicked? proceed? total-steps] patches-own [ name state flag] to setup3x2 ca ask patches [ if pxcor mod 10 = 0 [ set pcolor green ] if pycor mod 15 = 0 [ set pcolor green ] setup-lights3x2 ] end to setup-lights3x2 ; X line 1 let light11 patches with [ pxcor > 0 and pxcor < 10 and pycor > 0 and pycor < 15 ] let light12 patches with [ pxcor > 10 and pxcor < 20 and pycor > 0 and pycor < 15 ] let light13 patches with [ pxcor > 20 and pxcor < 30 and pycor > 0 and pycor < 15 ] ask light11 [ set pcolor red set name "light11"] ask light12 [ set pcolor red set name "light12"] ask light13 [ set pcolor red set name "light13"] ; X line 2 let light21 patches with [ pxcor > 0 and pxcor < 10 and pycor > 15 and pycor < 30] let light22 patches with [ pxcor > 10 and pxcor < 20 and pycor > 15 and pycor < 30 ] let light23 patches with [ pxcor > 20 and pxcor < 30 and pycor > 15 and pycor < 30 ] ask light21 [ set pcolor red set name "light21"] ask light22 [ set pcolor red set name "light22"] ask light23 [ set pcolor red set name "light23"] ask patches with [ name = "light21" or name = "light22" or name = "light13" ][ set pcolor yellow set state true ] set total-steps 1 end to setup5x5 ca set total-steps 1 set counter 0 ask patches [ set state false set name "light00" if pxcor mod 6 = 0 [ set pcolor green ] if pycor mod 6 = 0 [ set pcolor green ] ] setup-lights5x5 ask patches with [ ; name = "light24" or ; name = "light25" or name = "light32" or name = "light55" or name = "light23" or name = "light41" or name = "light52" or name = "light11" ][ set pcolor yellow set state true ] end to go check-mouse end to solve-game3x2 let i 3 let j 0 repeat 2 [ set i i - 1 set j 0 repeat 3 [ set j j + 1 let my-name word word "light" i j ask patches with [ name = my-name ] [ let a read-from-string (item 5 name) let b read-from-string (item 6 name) let up-name word word "light" ( a + 1 ) b ask patches with [ name = up-name] [ if pcolor = yellow [ set pcolor red if proceed? = false [ set total-steps total-steps + 1 ] set proceed? true ] ] if proceed? = true [ flip-lights my-name user-message " Press OK to proceed for next step"] ] ] ] ifelse count patches with [ pcolor = yellow ] > 0 [ user-message " This configuration is not solve able" ] [ user-message word "Game solved in steps: " total-steps ] end to solve-game let i 5 let j 0 repeat 4 [ set i i - 1 set j 0 repeat 5 [ set j j + 1 let my-name word word "light" i j ask patches with [ name = my-name ] [ let a read-from-string (item 5 name) let b read-from-string (item 6 name) let up-name word word "light" ( a + 1 ) b ask patches with [ name = up-name] [ if pcolor = yellow [ set pcolor red if proceed? = false [ set total-steps total-steps + 1 ] set proceed? true ] ] if proceed? = true [ flip-lights my-name user-message " Press OK to proceed for next step"] ] ] ] ifelse count patches with [ pcolor = yellow ] > 0 [ user-message " This configuration is not solve able" ] [ user-message word "Game solved in steps: " total-steps ] end to flip-lights [ my-name ] ask patches with [ name = my-name] [ ifelse pcolor = yellow [set pcolor red][set pcolor yellow] ] set proceed? false let a read-from-string (item 5 name) let b read-from-string (item 6 name) let left-name word word "light" a ( b - 1 ) ask patches with [ name = left-name] [ ifelse pcolor = yellow [set pcolor red][set pcolor yellow] ] let right-name word word "light" a ( b + 1 ) ask patches with [ name = right-name] [ ifelse pcolor = yellow [set pcolor red][set pcolor yellow] ] let bottom-name word word "light" ( a - 1 ) b ask patches with [ name = bottom-name] [ ifelse pcolor = yellow [set pcolor red][set pcolor yellow] ] end to check-mouse ifelse mouse-down? [ if not mouse-clicked? [ set mouse-clicked? true ask patch mouse-xcor mouse-ycor [ ; Start ; ifelse pcolor = yellow [set pcolor red][ set pcolor yellow ] ask patches with [ pcolor != green and name = [name] of patch mouse-xcor mouse-ycor] [ ifelse state = false [set pcolor yellow set state true][set pcolor red set state false] ] let a read-from-string (item 5 name) let b read-from-string (item 6 name) let left-name word word "light" a (b + 1) ask patches with [ pcolor != green and name = left-name] [ ifelse state = false [set pcolor yellow set state true][set pcolor red set state false] ] let right-name word word "light" a ( b - 1) ask patches with [ pcolor != green and name = right-name] [ ifelse state = false [set pcolor yellow set state true][set pcolor red set state false] ] let top-name word word "light" (a + 1) b ask patches with [ pcolor != green and name = top-name] [ ifelse state = false [set pcolor yellow set state true][set pcolor red set state false] ] let botton-name word word "light" ( a - 1) b ask patches with [ pcolor != green and name = botton-name] [ ifelse state = false [set pcolor yellow set state true][set pcolor red set state false] ] ] ;end ] ] [ set mouse-clicked? false ] end to setup-lights5x5 ; X line 1 let light11 patches with [ pxcor > 0 and pxcor < 6 and pycor > 0 and pycor < 6 ] let light12 patches with [ pxcor > 6 and pxcor < 12 and pycor > 0 and pycor < 6 ] let light13 patches with [ pxcor > 12 and pxcor < 18 and pycor > 0 and pycor < 6 ] let light14 patches with [ pxcor > 18 and pxcor < 24 and pycor > 0 and pycor < 6 ] let light15 patches with [ pxcor > 24 and pxcor < 30 and pycor > 0 and pycor < 6 ] ask light11 [ set pcolor red set name "light11"] ask light12 [ set pcolor red set name "light12"] ask light13 [ set pcolor red set name "light13"] ask light14 [ set pcolor red set name "light14"] ask light15 [ set pcolor red set name "light15"] ; X line 2 let light21 patches with [ pxcor > 0 and pxcor < 6 and pycor > 6 and pycor < 12 ] let light22 patches with [ pxcor > 6 and pxcor < 12 and pycor > 6 and pycor < 12 ] let light23 patches with [ pxcor > 12 and pxcor < 18 and pycor > 6 and pycor < 12 ] let light24 patches with [ pxcor > 18 and pxcor < 24 and pycor > 6 and pycor < 12 ] let light25 patches with [ pxcor > 24 and pxcor < 30 and pycor > 6 and pycor < 12 ] ask light21 [ set pcolor red set name "light21"] ask light22 [ set pcolor red set name "light22"] ask light23 [ set pcolor red set name "light23"] ask light24 [ set pcolor red set name "light24"] ask light25 [ set pcolor red set name "light25"] ; X line 3 let light31 patches with [ pxcor > 0 and pxcor < 6 and pycor > 12 and pycor < 18 ] let light32 patches with [ pxcor > 6 and pxcor < 12 and pycor > 12 and pycor < 18 ] let light33 patches with [ pxcor > 12 and pxcor < 18 and pycor > 12 and pycor < 18 ] let light34 patches with [ pxcor > 18 and pxcor < 24 and pycor > 12 and pycor < 18 ] let light35 patches with [ pxcor > 24 and pxcor < 30 and pycor > 12 and pycor < 18 ] ask light31 [ set pcolor red set name "light31"] ask light32 [ set pcolor red set name "light32"] ask light33 [ set pcolor red set name "light33"] ask light34 [ set pcolor red set name "light34"] ask light35 [ set pcolor red set name "light35"] ; X line 4 let light41 patches with [ pxcor > 0 and pxcor < 6 and pycor > 18 and pycor < 24 ] let light42 patches with [ pxcor > 6 and pxcor < 12 and pycor > 18 and pycor < 24 ] let light43 patches with [ pxcor > 12 and pxcor < 18 and pycor > 18 and pycor < 24 ] let light44 patches with [ pxcor > 18 and pxcor < 24 and pycor > 18 and pycor < 24 ] let light45 patches with [ pxcor > 24 and pxcor < 30 and pycor > 18 and pycor < 24 ] ask light41 [ set pcolor red set name "light41"] ask light42 [ set pcolor red set name "light42"] ask light43 [ set pcolor red set name "light43"] ask light44 [ set pcolor red set name "light44"] ask light45 [ set pcolor red set name "light45"] ; X line 5 let light51 patches with [ pxcor > 0 and pxcor < 6 and pycor > 24 and pycor < 30 ] let light52 patches with [ pxcor > 6 and pxcor < 12 and pycor > 24 and pycor < 30 ] let light53 patches with [ pxcor > 12 and pxcor < 18 and pycor > 24 and pycor < 30 ] let light54 patches with [ pxcor > 18 and pxcor < 24 and pycor > 24 and pycor < 30 ] let light55 patches with [ pxcor > 24 and pxcor < 30 and pycor > 24 and pycor < 30 ] ask light51 [ set pcolor red set name "light51"] ask light52 [ set pcolor red set name "light52"] ask light53 [ set pcolor red set name "light53"] ask light54 [ set pcolor red set name "light54"] ask light55 [ set pcolor red set name "light55"] if mouse-down? [ ask light11 [ set pcolor white ] ] end
There are 3 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
lights-out.png | preview | Preview for 'lights-out' | about 5 years ago, by Muhammad Tausif | Download |
This model does not have any ancestors.
This model does not have any descendants.