Author Topic: Battleship with AI  (Read 13964 times)

0 Members and 1 Guest are viewing this topic.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Battleship with AI
« Reply #15 on: May 28, 2018, 01:48:49 pm »
Heya bplus,

I've been following this for a while now - nice progress!

For the past week or so, I've been mucking around with a recursive solver for the AI engine. Below you can see what I decided to push to the forums. It's got a very rudimentary setup - 10x10 ocean, with a weighted random distribution of ships. The algo itself can be tweaked heavily - at this point it seems to work nicely, but maybe a few numbers could change when it's time to play against a human (or itself I suppose). Anyway, watch and be inspired. Feel free to ignore it, too:

Code: QB64: [Select]
  1. '. = open, S = ship, H = hit, ~ = Miss
  2.  
  3.  
  4. DIM SHARED ocean(10, 10) AS STRING
  5.  
  6. FOR i = 1 TO 10
  7.     FOR j = 1 TO 10
  8.         IF RND > (10 - i) * (10 - j) * .05 THEN
  9.             ocean(i, j) = "S"
  10.         ELSE
  11.             ocean(i, j) = "."
  12.         END IF
  13.     NEXT
  14.  
  15. CALL printmap
  16.     CALL tryhit(1, 10, 1, 10)
  17. LOOP UNTIL checkdone(1, 10, 1, 10) = 1
  18.  
  19. SUB tryhit (xstart, xend, ystart, yend)
  20.     IF xstart < 1 THEN xstart = 1
  21.     IF xend > 10 THEN xend = 10
  22.     IF ystart < 1 THEN ystart = 1
  23.     IF yend > 10 THEN yend = 10
  24.     IF checkdone(xstart, xend, ystart, yend) = 0 THEN
  25.         xguess = INT(xstart + RND * (xend - xstart + 1))
  26.         yguess = INT(ystart + RND * (yend - ystart + 1))
  27.         _DELAY .1
  28.         SELECT CASE ocean(xguess, yguess)
  29.             CASE "S"
  30.                 ocean(xguess, yguess) = "H"
  31.                 CALL printmap
  32.                 FOR k = 1 TO 64
  33.                     CALL tryhit(xguess - 2, xguess + 2, yguess - 2, yguess + 2)
  34.                 NEXT
  35.             CASE "H"
  36.                 ocean(xguess, yguess) = "H"
  37.                 CALL printmap
  38.                 FOR k = 1 TO 8
  39.                     CALL tryhit(xguess - 2, xguess + 2, yguess - 2, yguess + 2)
  40.                 NEXT
  41.             CASE ".", "~"
  42.                 ocean(xguess, yguess) = "~"
  43.                 CALL printmap
  44.                 CALL tryhit(xstart, xend, ystart, yend)
  45.         END SELECT
  46.     END IF
  47.  
  48. FUNCTION checkdone (xstart, xend, ystart, yend)
  49.     done = 1
  50.     FOR i = xstart TO xend
  51.         FOR j = ystart TO yend
  52.             IF ocean(i, j) = "." THEN
  53.                 done = 0
  54.             END IF
  55.         NEXT
  56.     NEXT
  57.     checkdone = done
  58.  
  59. SUB printmap
  60.     CLS
  61.     counter1 = 0
  62.     counter2 = 0
  63.     counter3 = 0
  64.     counter4 = 0
  65.     FOR i = 1 TO 10
  66.         FOR j = 1 TO 10
  67.             LOCATE j * 2, i * 3
  68.             PRINT ocean(i, j)
  69.             IF ocean(i, j) = "." THEN counter1 = counter1 + 1
  70.             IF ocean(i, j) = "~" THEN counter2 = counter2 + 1
  71.             IF ocean(i, j) = "S" THEN counter3 = counter3 + 1
  72.             IF ocean(i, j) = "H" THEN counter4 = counter4 + 1
  73.         NEXT
  74.     NEXT
  75.     LOCATE 20, 60: PRINT "."; counter1
  76.     LOCATE 21, 60: PRINT "~"; counter2
  77.     LOCATE 22, 60: PRINT "S"; counter3
  78.     LOCATE 23, 60: PRINT "H"; counter4
  79.     IF counter3 = 0 THEN END
  80.  
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Battleship with AI
« Reply #16 on: May 28, 2018, 03:00:33 pm »
Hi STxAxTIC

I do not understand your setup of ships so I borrowed code from Battleship, autosetup.
Code: QB64: [Select]
  1. '. = open, S = ship, H = hit, ~ = Miss
  2.  
  3.  
  4. DIM SHARED ocean(10, 10) AS STRING
  5.  
  6. FOR s = 1 TO 5
  7.     IF s < 3 THEN sl = s + 1 ELSE sl = s 'ship lengths
  8.     OK = 0
  9.     WHILE OK = 0
  10.         shipHor = rand(0, 1)
  11.         IF shipHor = 1 THEN
  12.             sy = rand(1, 10)
  13.             sx = rand(1, 10 - sl)
  14.             OK = -1
  15.             FOR xx = 0 TO sl - 1
  16.                 IF ocean(sx + xx, sy) = "S" THEN OK = 0: EXIT FOR
  17.             NEXT
  18.             IF OK THEN
  19.                 FOR xx = 0 TO sl - 1
  20.                     ocean(sx + xx, sy) = "S"
  21.                 NEXT
  22.             END IF
  23.         ELSE
  24.             sx = rand(1, 10)
  25.             sy = rand(1, 10 - sl)
  26.             OK = -1
  27.             FOR yy = 0 TO sl - 1
  28.                 IF ocean(sx, sy + yy) = "S" THEN OK = 0: EXIT FOR
  29.             NEXT
  30.             IF OK THEN
  31.                 FOR yy = 0 TO sl - 1
  32.                     ocean(sx, sy + yy) = "S"
  33.                 NEXT
  34.             END IF
  35.         END IF
  36.     WEND
  37. FOR y = 1 TO 10
  38.     FOR x = 1 TO 10
  39.         IF ocean(x, y) <> "S" THEN ocean(x, y) = "."
  40.     NEXT
  41.  
  42. CALL printmap
  43.     CALL tryhit(1, 10, 1, 10)
  44. LOOP UNTIL checkdone(1, 10, 1, 10) = 1
  45.  
  46. SUB tryhit (xstart, xend, ystart, yend)
  47.     IF xstart < 1 THEN xstart = 1
  48.     IF xend > 10 THEN xend = 10
  49.     IF ystart < 1 THEN ystart = 1
  50.     IF yend > 10 THEN yend = 10
  51.     IF checkdone(xstart, xend, ystart, yend) = 0 THEN
  52.         xguess = INT(xstart + RND * (xend - xstart + 1))
  53.         yguess = INT(ystart + RND * (yend - ystart + 1))
  54.         _DELAY .1
  55.         SELECT CASE ocean(xguess, yguess)
  56.             CASE "S"
  57.                 ocean(xguess, yguess) = "H"
  58.                 CALL printmap
  59.                 FOR k = 1 TO 64
  60.                     CALL tryhit(xguess - 2, xguess + 2, yguess - 2, yguess + 2)
  61.                 NEXT
  62.             CASE "H"
  63.                 ocean(xguess, yguess) = "H"
  64.                 CALL printmap
  65.                 FOR k = 1 TO 8
  66.                     CALL tryhit(xguess - 2, xguess + 2, yguess - 2, yguess + 2)
  67.                 NEXT
  68.             CASE ".", "~"
  69.                 ocean(xguess, yguess) = "~"
  70.                 CALL printmap
  71.                 CALL tryhit(xstart, xend, ystart, yend)
  72.         END SELECT
  73.     END IF
  74.  
  75. FUNCTION checkdone (xstart, xend, ystart, yend)
  76.     done = 1
  77.     FOR i = xstart TO xend
  78.         FOR j = ystart TO yend
  79.             IF ocean(i, j) = "." THEN
  80.                 done = 0
  81.             END IF
  82.         NEXT
  83.     NEXT
  84.     checkdone = done
  85.  
  86. SUB printmap
  87.     CLS
  88.     counter1 = 0
  89.     counter2 = 0
  90.     counter3 = 0
  91.     counter4 = 0
  92.     FOR i = 1 TO 10
  93.         FOR j = 1 TO 10
  94.             LOCATE j * 2, i * 3
  95.             PRINT ocean(i, j)
  96.             IF ocean(i, j) = "." THEN counter1 = counter1 + 1
  97.             IF ocean(i, j) = "~" THEN counter2 = counter2 + 1
  98.             IF ocean(i, j) = "S" THEN counter3 = counter3 + 1
  99.             IF ocean(i, j) = "H" THEN counter4 = counter4 + 1
  100.         NEXT
  101.     NEXT
  102.     LOCATE 20, 60: PRINT "."; counter1
  103.     LOCATE 21, 60: PRINT "~"; counter2
  104.     LOCATE 22, 60: PRINT "S"; counter3
  105.     LOCATE 23, 60: PRINT "H"; counter4
  106.     IF counter3 = 0 THEN END
  107.  
  108. FUNCTION rand (lo, hi)
  109.     rand = INT(RND * (hi - lo + 1)) + lo
  110.  
  111.  

I can see your code better now working over a hit area. It leaves a miss occasionally but not bad for random process!

The trouble with recursive process, is that it must be interrupted for the Player to take his turn after each and every try.
Can your process stop, let the other player take a shot and then pick up where it left off?

Well I still don't fully understand how it is working over the hit area but I will see what I can do... :)
« Last Edit: May 28, 2018, 03:07:39 pm by bplus »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Battleship with AI
« Reply #17 on: May 28, 2018, 03:12:57 pm »
Hello,

Dang, you caught the post before I could mod it. I'll think harder about whether the whole idea was a good one when I;m not in a terrible rush. For now, here is one tweak that made it more accurate from my basic testing:

Code: QB64: [Select]
  1. '. = open, S = ship, H = hit, ~ = Miss
  2.  
  3.  
  4. DIM SHARED ocean(10, 10) AS STRING
  5.  
  6. FOR i = 1 TO 10
  7.     FOR j = 1 TO 10
  8.         IF RND > (10 - i) * (10 - j) * .05 THEN
  9.             'IF i = 5 THEN
  10.             ocean(i, j) = "S"
  11.         ELSE
  12.             ocean(i, j) = "."
  13.         END IF
  14.     NEXT
  15.  
  16. CALL printmap
  17.     CALL tryhit(1, 10, 1, 10)
  18. LOOP UNTIL checkdone(1, 10, 1, 10) = 1
  19.  
  20. SUB tryhit (xstart, xend, ystart, yend)
  21.     IF xstart < 1 THEN xstart = 1
  22.     IF xend > 10 THEN xend = 10
  23.     IF ystart < 1 THEN ystart = 1
  24.     IF yend > 10 THEN yend = 10
  25.     IF checkdone(xstart, xend, ystart, yend) = 0 THEN
  26.         xguess = INT(xstart + RND * (xend - xstart + 1))
  27.         yguess = INT(ystart + RND * (yend - ystart + 1))
  28.         _DELAY .1
  29.         SELECT CASE ocean(xguess, yguess)
  30.             CASE "S", "H"
  31.                 ocean(xguess, yguess) = "H"
  32.                 CALL printmap
  33.                 FOR k = 1 TO 64
  34.                     CALL tryhit(xguess - 1, xguess + 1, yguess - 1, yguess + 1)
  35.                     CALL tryhit(xguess - 2, xguess + 2, yguess - 2, yguess + 2)
  36.                 NEXT
  37.             CASE ".", "~"
  38.                 ocean(xguess, yguess) = "~"
  39.                 CALL printmap
  40.         END SELECT
  41.     END IF
  42.  
  43. FUNCTION checkdone (xstart, xend, ystart, yend)
  44.     done = 1
  45.     FOR i = xstart TO xend
  46.         FOR j = ystart TO yend
  47.             IF ocean(i, j) = "." THEN
  48.                 done = 0
  49.             END IF
  50.         NEXT
  51.     NEXT
  52.     checkdone = done
  53.  
  54. SUB printmap
  55.     CLS
  56.     counter1 = 0
  57.     counter2 = 0
  58.     counter3 = 0
  59.     counter4 = 0
  60.     FOR i = 1 TO 10
  61.         FOR j = 1 TO 10
  62.             LOCATE j * 2, i * 3
  63.             PRINT ocean(i, j)
  64.             IF ocean(i, j) = "." THEN counter1 = counter1 + 1
  65.             IF ocean(i, j) = "~" THEN counter2 = counter2 + 1
  66.             IF ocean(i, j) = "S" THEN counter3 = counter3 + 1
  67.             IF ocean(i, j) = "H" THEN counter4 = counter4 + 1
  68.         NEXT
  69.     NEXT
  70.     LOCATE 20, 60: PRINT "."; counter1
  71.     LOCATE 21, 60: PRINT "~"; counter2
  72.     LOCATE 22, 60: PRINT "S"; counter3
  73.     LOCATE 23, 60: PRINT "H"; counter4
  74.     IF counter3 = 0 THEN END
  75.  
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Battleship with AI
« Reply #18 on: May 28, 2018, 03:44:15 pm »
I have to warn, games are usually over (with Battleship 5-AI) leaving 30-40% ocean left undisturbed. I will have to run some stats.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Battleship with AI
« Reply #19 on: May 28, 2018, 04:07:56 pm »
Hi BPlus. I have found that you are not testing whether a player twice (or more than once) shoots at the same place. My version is watching this. I have a question about the used BMP pictures. Are these your extra programs outputs saved as bitmaps or do you use any graphics program?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Battleship with AI
« Reply #20 on: May 28, 2018, 06:17:56 pm »
Hi Petr,

Just like human players, my AI tracks whether it has shot at a cell or not with the hits(x, y) array.

If the idiot player wants to shoot at the same place over and over, let him! The board is tracking his shots so not needed to tell him he being wasteful of shots.

I don't understand your question of graphics used, allot of image files are used, just check out the folder loaded with them!
(Sorry, I am in a bit of a rush...)

Append: OK I think you are asking if these image files were created by the code? No, Johnno has been my supplier of image and sound files. We've collaborated on a number of projects. I did create code to generate the fire directly under the Black Battleship in the splash screen at the beginning.

Oh also, the squares that the Player has already tried (and missed) are signaled on the game board by a lighter, whiter shade water tile. Petr, maybe you did not notice the lighter shade? I myself could not see the difference in regular water tile and a water tile signaling a miss unless the tiles were side by side. In summary, the Player's misses are signaled to the Player, even if they are not checked in code.


Hi all,

The games are running much fiercer than I expected. To count how long a game takes by how much ocean remains undisturbed by hits or misses, I added this code to 5-AI at the end of the game loop:
Code: QB64: [Select]
  1. ahits = 0
  2. amisses = 0
  3. aocean = 0
  4. FOR y = 0 TO 9
  5.     FOR x = 0 TO 9
  6.         IF hits(x, y) > 0 THEN
  7.             ahits = ahits + 1
  8.         ELSEIF hits(x, y) = 0 THEN
  9.             aocean = aocean + 1
  10.         ELSE
  11.             amisses = amisses + 1
  12.         END IF
  13.     NEXT
  14. rgb 999
  15. PRINT "AI hits ="; ahits
  16. PRINT "AI misses ="; amisses
  17. PRINT "Undisturbed ocean ="; aocean
  18.  

I collected data from 25 games that I entered into this text file: 5-AI stats.txt attached. The first 14 items are my wins and the last 11 are the AI's wins.

I added up and averaged with this code:
Code: QB64: [Select]
  1. 'add stats
  2. OPEN "5-AI stats.txt" FOR INPUT AS #1
  3. FOR i = 1 TO 26
  4.     INPUT #1, fline$
  5.     IF i < 15 THEN pt = pt + VAL(fline$) ELSE at = at + VAL(fline$)
  6. PRINT "Player win average undisturbed ocean ="; pt / 14
  7. PRINT "AI win average undisturbed ocean ="; at / 11
  8. PRINT "Total average undisturbed ocean ="; (at + pt) / 25
  9.  

And the results are here in last screen shot.

56% +/- of ocean is undisturbed in game, that means on Average only 44 shots are taken before a winner is determined!!!
* 5-AI stats.txt (Filesize: 0.1 KB, Downloads: 279)
Undisturbed ocean stats.PNG
* Undisturbed ocean stats.PNG (Filesize: 2.98 KB, Dimensions: 403x105, Views: 410)
« Last Edit: May 28, 2018, 08:05:20 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Battleship with AI
« Reply #21 on: May 28, 2018, 07:41:02 pm »
Hi Petr,

I have reread and thought more about your questions and comments and appended a longer reply in post above.

I hope I have answered your concerns.

FellippeHeitor

  • Guest
Re: Battleship with AI
« Reply #22 on: May 28, 2018, 08:49:05 pm »
You guys seem to be on fire with this one!

I'm going to try it and see if I have any issues with sound and image as you pointed out. I'll let you know.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Battleship with AI
« Reply #23 on: May 29, 2018, 08:56:43 am »
Of course for me the latest version of Battleship 5-AI 2018-05-24 runs fine on Windows 10 (Intel CORE i5, 7th gen) laptop.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Battleship with AI
« Reply #24 on: May 29, 2018, 12:54:51 pm »
Hi BPlus. I ask, because i like very much your BMP picture that contains text BATTLESHIP. Your fire effect i like too, so i use it as VIDEO TEXTUR for text :-D Without fast _MEM functions this time:

Code: QB64: [Select]
  1. texture& = _SCREENIMAGE
  2. Fire& = _NEWIMAGE(640, 75, 256)
  3. CONST xxmax = 640
  4. CONST yymax = 75
  5. CONST Xstep = 1
  6. CONST ystep = 1
  7.  
  8. DIM SHARED f(xxmax, yymax + 2)
  9. DIM SHARED pal&(300)
  10.  
  11. FOR x = 0 TO xxmax
  12.     f(x, yymax + 1) = INT(RND * 2) * 300
  13.     f(x, yymax + 2) = 300
  14. FOR i = 1 TO 100
  15.     fr = 240 * i / 100 + 15
  16.     pal&(i) = _RGB(fr, 0, 0)
  17.     pal&(i + 100) = _RGB(255, fr, 0)
  18.     pal&(i + 200) = _RGB(255, 255, fr)
  19. SCREEN _NEWIMAGE(1024, 768, 256)
  20. F$ = ENVIRON$("SYSTEMROOT") + "\fonts\BrushSci.ttf"
  21.  
  22. Text$ = "Thank you!"
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.     FireVideo
  30.     TexturedText Fire&, Text$, 300, 384, F$, 60
  31.     _DISPLAY
  32.     _LIMIT 50
  33.  
  34. SUB FireVideo
  35.     SHARED ticker
  36.     _DEST Fire&
  37.     FOR x = 1 TO xxmax - 1 'shift fire seed a bit
  38.         r = RND
  39.         IF r < .15 THEN
  40.             f(x, yymax + 1) = f(x - 1, yymax + 1)
  41.         ELSEIF r < .3 THEN
  42.             f(x, yymax + 1) = f(x + 1, yymax + 1)
  43.         ELSEIF r < .35 THEN
  44.             f(x, yymax + 1) = INT(RND * 2) * 300
  45.         END IF
  46.     NEXT
  47.     FOR y = 0 TO yymax 'fire based literally on 4 pixels below it like cellular automata
  48.         FOR x = 1 TO xxmax - 1
  49.             f(x, y) = max((f(x - 1, y + 1) + f(x, y + 1) + f(x + 1, y + 1) + f(x - 1, y + 2)) / 4 - 5, 0)
  50.             LINE (x * Xstep, y * ystep)-STEP(Xstep, ystep), pal&(f(x, y)), BF
  51.         NEXT
  52.     NEXT
  53.     ticker = ticker + .025
  54.  
  55.  
  56.  
  57.  
  58. SUB TexturedText (texture AS LONG, text AS STRING, X AS INTEGER, Y AS INTEGER, Font AS STRING, FontSize AS INTEGER) 'FontW, FontH)
  59.     SHARED f&, v&
  60.     De = _DEST: So = _SOURCE
  61.     IF f& = 0 THEN f& = _LOADFONT(Font$, FontSize, "MONOSPACE")
  62.     IF v& = 0 THEN
  63.         v& = _NEWIMAGE(LEN(text) * _FONTWIDTH(f&) * 3, 3 * _FONTHEIGHT(f&), 256)
  64.         COLOR 15
  65.         _FONT f&, v&
  66.         _DEST v&: PRINT text$
  67.         _DEST 0
  68.     END IF
  69.  
  70.     FOR TH = 0 TO _FONTHEIGHT(f&) + 10
  71.         FOR TW = 0 TO _FONTWIDTH(f&) * LEN(text$)
  72.             _SOURCE v&
  73.  
  74.             IF POINT(TW, TH) = 15 THEN
  75.                 _SOURCE texture&: _DEST 0
  76.                 PSET (X + TW, Y + TH), POINT(TW, 32 + (TH - 12))
  77.             END IF
  78.     NEXT TW, TH
  79.     _DEST De: _SOURCE So
  80.  
  81.  
  82.  
  83. FUNCTION max (a, b)
  84.     IF a < 64 THEN a = 64 'for always visible text
  85.     IF a > b THEN max = a ELSE max = b
  86.  
  87.  
  88.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Battleship with AI
« Reply #25 on: May 29, 2018, 03:25:50 pm »
Oh hey! very nice effect Petr!

I will study...

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Battleship with AI
« Reply #26 on: May 29, 2018, 11:38:59 pm »
@bplus
Nice Improvement with AI. Now, I'm not able to win computer. It wil be interesting to see a Computer vs Computer match.
@Petr
Nice effect!
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Battleship with AI
« Reply #27 on: May 30, 2018, 10:11:27 am »
@bplus
Nice Improvement with AI. Now, I'm not able to win computer. It wil be interesting to see a Computer vs Computer match.
@Petr
Nice effect!

Hi Ashish,

Thanks for you report, I can assume the program is running fine for you. It warms my heart to know the AI can beat you, that  is impressive. 

But don't be discouraged, you are human who has capability to learn and use intuition. Learn how AI plays and use some of it's methods then it is a 50/50 chance who wins, you or it. You will edge it out because you are more flexible and learn!

PS if you think computer versus computer might be interesting, give it a shot! I think it would be boring UNLESS the programs can learn and improve from playing each other. But overall, it's just a guessing game, a matter of probability and statistics unless the computer plays a human and can pick up on the human's lack of experience with game and probability. I don't know...

A big decision with the game is deciding whether to go with mod 3 coverage or mod 2, every 2 squares or every other square. Then there is some skill in switching mod coverage according to smallest ship sunk eg if all you have left to sink is the Carrier (5 holed) you need cover the remaining uncovered ocean systematically every 5 squares! But this was discussed earlier in thread.
« Last Edit: May 30, 2018, 10:27:47 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Battleship with AI
« Reply #28 on: May 31, 2018, 03:58:26 pm »
Well the results are in, Battleship 6 AI versus AI, the random coverage of every 2 squares clearly edges out random coverage of every other square. My instincts confirmed to go with every 2 squares to cover board faster when hunting down a ship for first hit (unless all the 3 or less length ships have been sunk.)

For 100 games in a row here is sample of results mod 2 - mod 3:
40-60
46-54
50-50 the closest they ever came!
31-69
...
I'd say 40 something versus 50 something was typical.
Battlseship 6 - AI 2 versus AI 3 (Computer)  20 games.PNG
* Battlseship 6 - AI 2 versus AI 3 (Computer) 20 games.PNG (Filesize: 3.15 KB, Dimensions: 487x69, Views: 383)
Battleship 6 - AI 2 versus AI 3 (Computer) 100 games.PNG
* Battleship 6 - AI 2 versus AI 3 (Computer) 100 games.PNG (Filesize: 2.97 KB, Dimensions: 515x62, Views: 379)
Battleship 6 - AI 2 versus AI 3 (Computer) 100 games 50-50.PNG
* Battleship 6 - AI 2 versus AI 3 (Computer) 100 games 50-50.PNG (Filesize: 2.9 KB, Dimensions: 509x80, Views: 391)

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Battleship with AI
« Reply #29 on: June 01, 2018, 10:26:24 am »
The result are amazing...
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials