wavesinaroom / my_odin_project_battleship

0 stars 0 forks source link

Adjacent slots #15

Open wavesinaroom opened 1 year ago

wavesinaroom commented 1 year ago

You can polish the intelligence of the computer player by having it try adjacent slots after getting a ‘hit’.

wavesinaroom commented 1 year ago

Well... good newsgh issue view 15 -c Implementing placeRandomShip method was easier than expected. This is not the end of the road though as I'm planning out to let the user choose number of ships for the game which is gonna match the number of ships cpu will have

wavesinaroom commented 1 year ago

[Older] Just migrated the cpuActions object literal to a new script while preserving tests passing

wavesinaroom commented 1 year ago

I'll definitely use coordinates for cpu AI

wavesinaroom commented 1 year ago

Alright, at this point I found out that using coordinates didn't return possible shots for the AI whereas working with missile would have. I'm coming back to missiles

wavesinaroom commented 1 year ago

There's an easier way to approach the problem without relying on a graph like data structure. As ships aren't piece that cover combinations of horizontal and vertical coordinates, predicting shots can be done by creating arrays of possible shots dynamically. I'll draw some stuf on the board to find out if I should change the strategy at this point

wavesinaroom commented 1 year ago

After some time doodling on Whiteboard, I found a solution that could work. It basically gets rid of the idea of using sort of graphs, instead this strategy creates arrays of positions after finding out target ship orientation from a simple math formula. As always, it must be tested to really know how good it is... we'll see ;)

wavesinaroom commented 1 year ago

checkAxis and generateAxis are done, so far so good

wavesinaroom commented 1 year ago

I think I'm done with getMoves method inside cpu object. It's time to test it thouroughly though before finishing of cpu ai. It's been great experience although painstaking

wavesinaroom commented 1 year ago

I'm done with the methods that I need for firing a random shot. Now I've got to connect them together inside a method that can be easily called from the GameManager changeTurn method

wavesinaroom commented 1 year ago

Testing fireRandomShot will require avoiding using the GameManager flow. That will isolate test to the cpu module exclusively

wavesinaroom commented 1 year ago

I musn't implement fireRandomShot in cpu module but in cpu section inside player.js

wavesinaroom commented 1 year ago

I could finally understand how to apply a mock. This one's for real :D

wavesinaroom commented 1 year ago

I've learned a lot from this project but I'm not able to finish it. This is the end of the road