billmei / battleboat Goto Github PK
View Code? Open in Web Editor NEWA JavaScript AI that beats humans at battleship.
Home Page: https://billmei.github.io/battleboat
License: MIT License
A JavaScript AI that beats humans at battleship.
Home Page: https://billmei.github.io/battleboat
License: MIT License
After running setDebug(true)
in the console the "Place Randomly and Start" button is revealed.
Place some boats (not all), then select "Place Randomly and Start".
The manually placed boats are visible, but the full set of 5 boats have been added to the board.
If the bot guesses a cell containing one of the manually placed cells an exception is thrown:
targetGrid.isUndamagedShip(x, y)
returns true
for the manually placed cell, but
targetFleet.findShipByCoords(x, y)
returns null
, so
targetFleet.findShipByCoords(x, y).incrementDamage()
throws
"Uncaught TypeError: Cannot read property 'incrementDamage' of null".
The quick fix is to change the way the boats are added to the board to prevent this problem.
This bug highlights the discrepancy between the way boats are displayed and stored. I would suggest getting rid of targetGrid.isUndamagedShip(x, y)
in favor of targetFleet.findShipByCoords(x, y)
's response (the boat's internal representation) providing enough info about the state of the ship to determine if the cell is undamaged (it might even already).
Is there a strategy that is employed such that the AI always wins? I feel like a strategy isnt being employed by the ai aside from "find the next closest piece". I'd like to really make an AI that ASSUREDLY beats humans at this game
Excerpt from an email from me to @uniphil...
...
So going with the most likely square on a per-move basis might not always be ideal. For example, let's say you're looking for a length 2 ship, and the open squares on the board look like this:
o o o o o o o
The algorithm is going to favour:
O O O O O o o
For argument's sake, let's say the centre square is chosen first. 1/3 hit rate.
If the square is hit, you can choose left / right on the next move, so 50% there. So.. 1/3 chance of getting 2.5 moves to victory.
If the square isn't a hit (2/3), you'll then choose left / right corner. If it's a hit, it leaves you with a victory after 3 or 4 moves (3.5). If it's a miss, 4.5.
1/3 * 2.5 + 1/3 * 3.5 + 1/3 * 4.5 = 3.5 move average. Starting on the corners is similar and also yields a 3.5 average.
But!! These guys:
o O o O o o o
yield a (2.5 + 3 + 4.5) / 3 = 3.33 move average.
I'm sure there are better examples, but this shows that relying on an immediate probability cloud misses something on planning ahead. Integrating post-move-board-complexity would improve the solution...
Pondering how to not brute-force this. Merp.
Thoughts? @uniphil @Kortaggio @hdevalence
The issue is the google translate exntesion.
(translating websites for ur own language - in my case from english to polish one )
It makes it impossible to use the application - it is not possible to place ships while the page is translated.
Idk acutally if its only with polish language but i guess its the same with every other one.
Hello, apparantly your system is simply picking randomly a set of grid squares on alternate grids. Would it not be simpler just to go in some sort of structured direction? Also, if you're collecting win statistics using google, why not collect ship placement locations through it? That way you could see where people place most ships, for instance, very few people place ships on the very outside of the grid.
In case you expect players to play more than once, picking random locations makes sense, as they cannot pick a location well. Oh, one more thing, when the computer finds the '2' ship, you should change the square structure, plus the same with when the "2 and 3" ships are found. I don't think it does this, although I might be mistaken.
If I'm made a monumental failure, please do not hesitate to say.
Nothing happens when i click on the grid of enemy fleet.
Edit : Oops,I had not placed all the ships before starting the game.
I tried this, but works with several bugs, the ships disapears.
And I have not modified what is necessary for the AI to position the ships and the others functionalities (as AI attack and random-placement button.
Can you tell me what I must edit to get that 'game mode' ?
(don't allow to place a ship right next to another)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.