New Posts  All Forums:Forum Nav:

Writing a simple AI?

post #1 of 8
Thread Starter 
I am in the process of making an AI for my Battleship game. (See Here to test it out so far). With my experience in java, writing an AI for my computer enemy is not that easy. Do you have any tips on making an AI? I can provide the source if needed. I just don't know how I would go about handling all the possible situations with this. And this is only battleship. I can't imagine something even harder.

Thnaks.
post #2 of 8
i like to build scales... kinda like risk management
for a battleship game you have each odject (ships) with there own dimentions. Have the computer pick a location and work as a grid pattern like target all the blacks on a checkerboard. If its a hit add one to a class variable and have it determine in what direction to fire the next volley. Use as many helper methods as you can and when writing AI i prefer to use risk assestment by sacaling and if the number gets to a certian point shoot there
post #3 of 8
It really depends on how sophisticated and deep you want to go with the AI.

I really enjoyed this book on the subject it was easy to follow and deep enough to keep it interesting throughout.
[ame="http://www.amazon.com/Programming-Game-Example-Mat-Buckland/dp/1556220782"]Amazon.com: Programming Game AI by Example (9781556220784): Mat Buckland: Books[/ame]

There is also the first chapter or so on the net from the website at
http://www.ai-junkie.com/books/toc_pgaibe.html

Other wise you can also look around on
http://altdevblogaday.org/ there are some good talks about what to implement that may be able to point you in a direction you would like to go.
Edited by Midpipps - 5/19/11 at 7:43am
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
Reply
post #4 of 8
Thread Starter 
I am not looking to be an AI specialist, but I am just looking for a way to solve my AI problem. And I am writing this in java, so a C++ book won't really help. Thanks anyways tho.
post #5 of 8
Well see that is where you are wrong you can take ideas from a C++ book and move them to java easily enough the main point is finding what kind of system you want to build and how to implement it. In fact some of the ideas in the book probably would be simpler to create in java.

Do you want a behavior system, a finite state machine, etc. do you want to be able to easily expand and change things if you find a behavior that you do not really care for. Do you just want them to follow a linear thought process and do the first action that checks true or do you want to weight the options.

To the original question you could make it choose every other square in a checkerboard pattern until it hit a target then search all around for more hits until you had a miss on all sides of the target. Or you could weight the squares and give them probabilities and go for ones with higher probabilities first. there are alot of options. or you could have it choose random squares that are not in an area with less squares then the shortest ship.
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
Reply
post #6 of 8
Clicky

This should keep you busy for a while
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
1100t Asus m4A78T-E HIS 5850 4G 
Hard DriveOS
60 SS, + 3T Windows 7 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
1100t Asus m4A78T-E HIS 5850 4G 
Hard DriveOS
60 SS, + 3T Windows 7 
  hide details  
Reply
post #7 of 8
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
1100t Asus m4A78T-E HIS 5850 4G 
Hard DriveOS
60 SS, + 3T Windows 7 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
1100t Asus m4A78T-E HIS 5850 4G 
Hard DriveOS
60 SS, + 3T Windows 7 
  hide details  
Reply
post #8 of 8
use AI algorithms. State space and search, or behavioral, or decision trees.
familiarize yourself with the algorithms first. it took me 1 week to learn to code AI state space and search algorithms (DFS,BFS,A*, Hill Climb, Djikstra)
the RULE for AI algorithms is PEAS.

Performance:define how fast it is, or what is the goal state and starting state
Environment:define the battle place, the rules, the things necessary to get the game done.
Actuator:What are the ACTIONS that AI can do (for battleship game, the actions usually consists of battleship placement and ship shot)
Sensor:How the AI sees its environment. in battleship game, how the AI determine where the enemy ship, what are probability of the kinds of enemy ship there after shooting a random location and get hit, so it will able to hit subsequent blocks with greater probability
Outdated
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8200 2.6 Ghz Asrock g31M-S R2 ATi 3870 2GB Kingston Value RAM 
Hard DriveOptical DriveOSMonitor
2TB WD Green+ 640GB WD Blue None Win 7 Ultimate 21.5 Dell 
KeyboardPowerCaseMouse
HP Wireless Keyboard 550W Cooler Master None Logitech cheap mouse 
Mouse Pad
none 
  hide details  
Reply
Outdated
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8200 2.6 Ghz Asrock g31M-S R2 ATi 3870 2GB Kingston Value RAM 
Hard DriveOptical DriveOSMonitor
2TB WD Green+ 640GB WD Blue None Win 7 Ultimate 21.5 Dell 
KeyboardPowerCaseMouse
HP Wireless Keyboard 550W Cooler Master None Logitech cheap mouse 
Mouse Pad
none 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming