PythonBattleshipGame icon indicating copy to clipboard operation
PythonBattleshipGame copied to clipboard

Complete function make_move_cpu

Open JorritWillaert opened this issue 6 years ago • 6 comments

The cpu has to make a 'smart move'. So, when something of a ship is hitted earlier, the cpu has to shoot where the ship is most likely to be.

image

JorritWillaert avatar Aug 27 '19 18:08 JorritWillaert

Could you elaborate what the code exactly does? It's not that easy to comprehend the logic here :)

wernersbacher avatar Sep 19 '19 07:09 wernersbacher

For sure ;)

What I would like to do, is first making a random move (like everone does in the beginning of the game), and if it is a hit, save it and try the next time an adjacent field (1 up, down, right or left, random chose between these four). If the random chose was a good one (suppose right), you know there's a ship lying horizontal. So, keep trying right and left (not longer up and down), until the ship is sunk. If the ship is sunk, but there are also other hits (for example when two ships are located next to each other), search for the next ship. If there are no longer 'possibilities' (one or more hits on a non-sunked ship), start again with random shots.

I hope this makes some sense. :)

May I thank you very much for your input! I really appreciate it!

Randpy

JorritWillaert avatar Sep 19 '19 11:09 JorritWillaert

Is the above code the code that you are working on? and it's not working?

Ratfink23 avatar Sep 19 '19 14:09 Ratfink23

This is what I would like that it’s doing, but I’m stuck...

Some help with this is therefore very welcome ;)

JorritWillaert avatar Sep 19 '19 15:09 JorritWillaert

This is what I would like that it’s doing, but I’m stuck...

I started on my own fork, I made the structure a little more clearer and added some helper functions and constants.

The game logic you want to have (recognise patterns) could be very hard for beginners, especially when there are several unsunken ships hit. I will look at this problem later on, but I bet we can't be the only people who programmed a battleship CPU yet...

wernersbacher avatar Sep 20 '19 09:09 wernersbacher

I know there's someone who has already made a CPU for a Battleship game.

I will take a small look at his code. It would also be very nice if you could help me a little further in your fork :)

Thanks again in advance!

JorritWillaert avatar Sep 20 '19 10:09 JorritWillaert