Previous part: Battleship player agent - 3

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` Maybe `ha` Next
 `ha` Item Ship `ha` Maybe `ha` Next
 `ha` Item Ship `ha` Maybe `ha` Next
 `ha` Item Ship `ha` Maybe `ha` Next
 `ha` Item Idle `ha` Maybe `ha` Next
 `ha` Item Ship `ha` Maybe `ha` Next
 `ha` Item Ship `ha` Maybe `ha` Next
 `ha` Item Idle `ha` Maybe `ha` Next
 `ha` Item Idle `ha` Maybe `ha` Next
 `ha` Item Idle `ha` Maybe `hv` Last

At the start of the game we know nothing aboout the opponent board:

known = enemy `yu` Mist 0

Next 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 enemy `lu'yp` to @List guess
 `yokl` Forth `ha` World `ha` render where

So we can check how precise do we shoot:

-|2  +|4  +|5  +|5  -|5  +|5  +|5  -|5  -|4  -|2

What if we finally start shooting?

shoot x _ = x `lu_` by Miss `lv` Nail `hv` by Bang `ho_` Shot `li` x

By 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.

Continue this tutorial