I'm making a battleship programming with scratch, and I'm having a little bit of trouble with the artificial intelligence.

What should each of the AI players do?
I'm planning for the game to have 3 AI players: easy, medium and hard.

Keep in mind...
1) placement of ships
2) locating player ships

Please post your thoughts before reading the next part...



Right now, I have...

Easy) Place ships randomly, but not overlapping.
Medium) Place ships randomly, but make sure they are not bordering vertically or horizontally.
Hard) Place ships like the medium AI.

The problem is, if people know that the two harder AIs don't put ships bordering, but the easy does, then they may use that information to make each of those levels easier, and it may not wind up being easy, medium and hard like it is supposed to be.


Easy) Randomly shoot in places that have not yet been targeted. Shoot around hits until those ships have been sunk

Medium) 50% of the time uses Easy's method, 50% Hard's

Hard) Randomly select a location to target. Make sure that the largest unsunken ship would fit in that spot. If not, repeat. Once largest ship would fit there, precede.

The problem is that the hard script does not narrow down its randomness based on the largest ship not fitting there, because once that ship is destroyed, the next (smaller) one will fit there, so after a few minutes, the script begins to take a long time. Should the script keep track of where it has already tried this pass in a list? Should I make the script hunt for the smaller ships first? (good for 1 shot method (right?!), but bad for 5 shot method right?))

Maybe it would be better to generate a grid of the least possible shots to locate the biggest ship, and this would only need to be run once in the beginning and whenever the biggest ship was sunk, provided that whenever a shot is made, the grid is changed accordingly. Sadly, it would be slightly complicated to have a separate target list from the "EnemyTarget" list, but it might be worth it.

Or maybe it would be better to generate the grid to of the least possible shots to locate the smaller ship... but there would still be some complicated list synchronization...

I'm also not sure the script is even doing what is supposed to properly, so I'm going to post some "code." For those of you unfamiliar with scratch, here is the color code...



and here is the "code" snippet...


Any help I could get over here would be much appreciated.

What do you guys think?
The reason I took twenty-four hours to reply to this particular question is that I am having difficulty deciding what I think a good AI would it. It's usually pretty straightforward; basically, try to implement the most computationally-feasible approach that a smart human player would try to use. In this case, that would be (0) If you know the player's general strategy, try to decide if they'll do something predictable or try hard to do the opposite of something predictable, otherwise (1) try to distribute guesses evenly across the board untill a hit, then (2) check the four cardinal directions around that hit to get a line, and finally (3) continue along that line until the ship sinks.
I'm not sure I want to deal with predictability, I was trying to use a grid formation to narrow down where the ships could be. I already have the easy player, which shoots randomly until a ship was hit, and then targets that particular ship. The script shown above is supposed to be for narrowing down where the largest ship could be, and shooting the first place that it could be (random). But it was taking to long, so I need to shorten it somehow or change how it works to make sure it will be faster.

Maybe the medium player should grid out for the small ship first, and then the hard the other way around? which way is more efficient? If it was going for the smallest ship first, i could delete any items that the ship would not fit in, because obviously no larger ship will fit there... would this be a good idea for hard, and medium is 50:50 still, or would there be a better thing to do for hard?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement