Racing (without GOGO)
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This section could give a general understanding of what the model is trying to show or explain.
HOW IT WORKS
This section could explain what rules the agents use to create the overall behavior of the model.
HOW TO USE IT
This section could explain how to use the model, including a description of each of the items in the interface tab.
THINGS TO NOTICE
This section could give some ideas of things for the user to notice while running the model.
THINGS TO TRY
This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.
EXTENDING THE MODEL
This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.
NETLOGO FEATURES
This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features.
RELATED MODELS
This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.
CREDITS AND REFERENCES
This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.
Comments and Questions
extensions [ gogo ] globals [ serial-port speed-out ;; globals for monitors speed-out2 slide ] turtles-own [ speed speed-other max-speed ] breed [ player-cars player-car ] breed [ other-cars other-car ] ;;;;;;;;;;;;;;;;;;;;;; ;; Setup procedures ;; ;;;;;;;;;;;;;;;;;;;;;; to setup clear-all check-for-gogo if Choose-Track = "Ring" [ ;; load maps import-pcolors "ringtrack.png" ] if Choose-Track = "Square" [ import-pcolors "squaretrack.png" ] if Choose-Track = "Hard" [ import-pcolors "hardtrack.png" ] ask patches with [ pcolor = 0.3 ] [ ;; tweak patch colors so they're easier to identify set pcolor black ] ask patches with [ pcolor = 64.4 ] [ set pcolor green ] set-traction ;; make halfway line ;; ask patches with [pxcor < -220 and abs pycor <= 1 and pcolor = black] [ ;; set pcolor yellow - 4 ;; ] ask patches with [pxcor > 200 and abs pycor <= 1 and pcolor = black] [ ;; make finishing line set pcolor yellow ] ;; make road ;; ask patches with [ pcolor = black ] ;; [ set pcolor random white ] make-cars ;; make-grass if View3D? [ ;; 3D view switch ifelse first-person? [ ride player-car 0 ] [ follow player-car 0 ] ] end to check-for-gogo if gogo-attached? = true [ if gogo:open? = false ;; set up gogo board [ set serial-port user-one-of "Select a port:" gogo:ports gogo:open serial-port repeat 5 [ if not gogo:ping [ user-message "The GoGo Board is not responding." ] ] gogo:talk-to-output-ports [ "a" "b" "c" "d" ] ] ] end to make-cars create-player-cars 1 [ ;; set up the player's car set size 20 set shape "car" set heading 0 set color blue set xcor max-pxcor * 0.85 set ycor 5 set speed 0 ] create-other-cars 5 [ ;; set up the competition set size 20 set shape "car" set heading 0 set color red move-to one-of patches with [ pcolor = black and pycor > 1 and pycor < 30 and pxcor > 225 and pxcor < 300] set speed-other 1.4 ] end to make-grass ask n-of 300 patches with [ pcolor = green ] ;; make grass to help visualize in 3D view [ sprout 1 [ set shape "plant" set color green + 2 set size 20 ] ] end to set-traction ;; add a slide factor based on weather if Weather = "Sunny" [ set slide 0 ] if Weather = "Rain" [ set slide 3 ] if Weather = "Snow" [ set slide 5 ] if Weather = "Random" [ ;; set chooser to one of the other weather types set Weather one-of [ "Sunny" "Rain" "Snow" ] set-traction ] end ;;;;;;;;;;;;;;;;;;; ;; go procedures ;; ;;;;;;;;;;;;;;;;;;; to go ask turtles [ if [pcolor] of patch-here = yellow ;; stop if you cross the yellow line --not working... [ set speed 0 ;; need to make one for other-car and player-car set shape "face happy" user-message "You won! Press 'halt' to play again!" ] ] ask player-cars [ let car-ahead one-of other turtles-on patches in-cone 10 30 set max-speed velocity-factor * 2.5 if [pcolor] of patch-ahead 1 = green ;; if the pach ahead is grass, report a crash and kill car [ set speed 0 set shape "x" user-message "You crashed! Press 'halt' and try again!" ] if gogo-attached? = true [ ifelse gogo:sensor 1 > 1000 ;; sensor reads over 1000 when untouched [ set speed speed - 0.03 ] ;; slows down when sensor 1 isn't pressed [ set speed speed - 0.03 + ( ( 1 + acceleration-factor ) / gogo:sensor 1 ) ] ;; speed up when pressing sensor 1 if gogo:sensor 2 < 1000 [ set speed speed - ( ( 10 - slide ) / gogo:sensor 2 ) ] ;; sensor 2 brakes if pressed ] if speed < 0 [ set speed 0 ] ;; keeps speed from going negative if speed > max-speed [ ;; sets max-velocity relative to velocity factor set speed max-speed ] if car-ahead != nobody [ set speed speed - 4 ] fd speed ;; moves set speed-out speed ;; sets speedometer monitor (may remove) ] ask other-cars [ ;; auto acceleration for other-car let car-ahead one-of other turtles-on patches in-cone 10 30 ;; looks for cars ahead if [pcolor] of patch-ahead 1 = green ;; if the pach ahead is grass, report a crash and stop the race [ set speed 0 set shape "x" die ] set speed-other speed-other + 0.1 ;; gradually speeds up if speed-other > 6 [ ;; sets a max speed of 6...may need tweaked set speed-other 6 ] if speed-other < 0 [ ;; keeps speed from going negative set speed-other 0 ] ifelse [pcolor] of patch-left-and-ahead 15 15 = green [ ;; looks forward and left for grass... fd ( .5 + slide ) rt ( random-float 30 - slide ) ] ;; turns slightly right if it sees grass...slide due to traction [ ifelse [pcolor] of patch-right-and-ahead 15 15 = green [ ;; looks forward and right for grass... fd ( .5 + slide ) lt ( random-float 30 - slide ) ] ;; turns slightly left if it sees grass...slide due to traction [ ifelse car-ahead != nobody [ ;; if car ahead slow way down set speed-other speed-other - 4 fd .5 ] [ fd speed-other ;; moves set speed-out2 speed-other ] ;; sets speed-out2 monitor (may remove once debugged) ] ] ] tick end ;;;;;;;;;;;;;;;;;;;;; ;; button commands ;; ;;;;;;;;;;;;;;;;;;;;; to speed-up ask player-cars [ set speed speed + 0.1 ] end to slow-down ask player-cars [ set speed speed - 0.2 ] end to turn-left ask player-cars [ fd ( slide + speed ) left 15 - slide ] end to turn-right ask player-cars [ fd ( slide + speed) right 15 - slide ] end
There are 5 versions of this model.
Attached files
No files
This model does not have any ancestors.
This model does not have any descendants.