Previous chapter ⋅ Full source code ⋅ Next chapter
If we are going to shoot, how do we get to know the result? In a real life environment, we would get this information by some network protocol. But again, for the sake of simplicity, we put the information about an opponent ship and probabily distribution together.
enemy = Nonempty @List
`ha` Item Idle `ha` Next
`ha` Item Ship `ha` Next
`ha` Item Ship `ha` Next
`ha` Item Ship `ha` Next
`ha` Item Idle `ha` Next
`ha` Item Ship `ha` Next
`ha` Item Ship `ha` Next
`ha` Item Idle `ha` Next
`ha` Item Idle `ha` Next
`ha` Item Idle `ha` LastAt the start of the game we know nothing about the opponent board:
known = by enemy `yu` Mist 0Next we need to calculate probabily distribution:
guess = that `hv_` distribute fleet `he'he'hv` to known… and merge it with an opponent board:
main = to @List `hv` by enemy `lu'yp` to @List `hv` guess
`yokl` Forth `ha` World `ha` render whereSo we can check how precise do we shoot:
-|2 +|4 +|5 +|5 -|5 +|5 +|5 -|5 -|4 -|2What if we finally start shooting?
shoot x _ = x `lu_` by Miss `lv` Nail `hv` by Bang `ho_` Shot `li` xBy traversing the board from left to right…
main = to @List enemy `lu'yp` to @List guess
`yokl` Forth `ha` World `ha` render `ha` (shoot `hj`)… we could prove that everything is working as expected:
-|2 +|4 +|5 +|5 -|5 +|5 +|5 -|5 -|4 -|2
-|- +|+ +|+ +|+ -|- +|+ +|+ -|- -|- -|-However, we don’t get any information about sunk ships. Let’s fix it.