Set a variable set when an entered point matches the given with a button press, then remain after when new points are added


#1

I’m working on a version of Battle Ship in Desmos for students to work on coordinate graphing. I have the capture, last value, and history feature working, but I want a point to drop in showing a hit when the coordinate is entered then have it remain there.

I currently have it working so that when (2,2) is entered it shows the “HIT” label, but once you submit another point the label disappears again. I’ve played with .timeSincePress and .pressCount, but I can’t get anything that will have the variable remain unchanged once the point is added to the list.

Any thoughts or suggestions are welcome!

Ryan


#2

There are two different options for resolving this that I came across. For both options, I added a correctness checker in the graph itself. Essentially yielding 1, if their point would hit the ship and 0 if it misses.

The What
Option 1 is slightly less coding. Uses conditions to decide how to label a point within the set you have already created.

Option 2 is more coding. Uses conditions to decide how to create two sets of points. The set of misses and the set of hits. This is more flexible in terms of color coding or referencing the list in a future slide. This reference might tell them how many misfirings they had and what points they were. You could also use it to count the hits. So in the graph itself you might have {__ hits out of __ }and {__ shots fired}". You are able to add labels which reference variables within the graph itself. You could make other conditional sets if you wanted a list of different ships (battle ship, carrier, etc. and keep track of them separately.

The How

Option1:

#I used the point label for the recent points, but you could also assign it to the history  (i.e. alist and blist) 
#You cant color code difference between miss and hit, but it's less code (included below)
#pointLabel("h_istory"): when this.number("H_{it}")=1 "Hit!" otherwise "Miss!"
pointLabel("r_ecent"): when this.number("H_{it}")=1 "Hiiiiit!" otherwise "Miss!

Option 2: Add captures for hits and misses and plot the two lists separately.

#Therse are the conditions for capturing a hit vs. capturing a miss, based on the correctness checker that I used in the graph itself.
capture("Hita"): when graph1.number("H_{it}")=1 graph1.number("a_{recent}") otherwise -10
capture("Hitb"): when graph1.number("H_{it}")=1 graph1.number("b_{recent}") otherwise -10
capture("Missa"): when graph1.number("H_{it}")=0 graph1.number("a_{recent}") otherwise -10
capture("Missb"): when graph1.number("H_{it}")=0 graph1.number("b_{recent}") otherwise -10

#This creates separate lists based on the conditional found on the button tab (above)
numberList("H_{ita}"): check1.history("Hita")
numberList("H_{itb}"): check1.history("Hitb")
numberList("M_{issa}"): check1.history("Missa")
numberList("M_{issb}"): check1.history("Missb")

https://teacher.desmos.com/activitybuilder/custom/5c08a862d223ec0b2dd407af


#3

Such a simple solution! I don’t know how I didn’t think of setting up two separate capture lists. Thanks so much!


#4

I am glad it did the trick. I spent most my time trying to think of how to split the capture list you made. Took me awhile to realize I could use conditions to create the lists separately from the start.