Artificial Intelligence with php

I probably know the answer already but just thought I would ask just in case, can you create some sort of computer AI with php and mySQL for a browser game I’m working on? I have read a little about ALICE but that seems to be for chat engines or forums.

What I would like to do is have a computer managed team football (soccer) play against a human team and realistically simulate the result. Are there any tutorials or guides on creating a chess brower game with php that may give me some help with this as I would imagine this is similar.

Have had a look on Google but the scripts are mainly for multiplayer only not for versus computer player. I am guessing the best way is a lot of if statements that have to run through when an event occurs and those events are based on other events that have happened. I think I can track where the ball is on the pitch so maybe I have a chance of doing it with this method?

The next big thing is to get the computer to play out the matches itself. Maybe a bit too ambitious.

Oooh, that will be interesting!

Basically the way I’d go about it is to calculate all of your possible moves, and what they could do about it. Calculate the probability of winning for each move, and use that calculated move.

If you want to increase/decrease difficulty level, go for the higher/lower percentage chance of winning.

However, with a football simulation that would be much harder. Thats because there are trillions of possibilities in the game, and working based on long-term probability isn’t ideal.

Overall I’d say PHP isn’t the best programming language to use; I’d use something like Java or anything.net because of threading abilities.

Chess is easier as it is turn based. How are you going to deal with real time processing in php? You need to know where the ball and players are at any given time.

Edit: You could probably do a sort of championship manager game where you choose the players and the formation and the computer works out who wins. Of course displaying the game to the user is going to be difficult.

I think I can track where the ball is on the pitch by splitting the pitch into a grid. Another way I was going to try and calculate computer teams playing each other was by using the ratings for attack, defense, midfield and throwing in a rand value to change things slightly.

As I said maybe a little ambitious but something I will try and get working. Will let you know how i get on.

Are there any tutorials or guides on creating a chess brower game with php that may give me some help with this as I would imagine this is similar.

Chess and your soccer game are vastly different in terms of AI. With chess, the AI is essentially a search tree that runs for as long as is allowed (or until it returns win) and returns the best move. This is not computationally possible if you now have 22 pieces that can move simultaneously. What you need to do is concentrate on rules for your players.

Start off with a player class that runs for a ball and kicks it towards the goal. Now start defining rules:

  • players on the same team stop heading for the ball if one of them is at it
  • players won’t kick for the goal if something is in the way
  • players will go left/right of the thing that is in the way to get to the goal
  • players will only do this for 5 ticks before breaking and passing the ball
  • mid fielders will pass the ball to forwards at x,y

I have no idea why you’d attempt this in php, but good luck :slight_smile:

Thanks hash for the ideas.

Why am I creating this? I have bought commercial software to play this type of game, Football Manager, Championship Manager, but thought that there were things not included that could have been. I am even thinking of turning this into an open source project and set up a community to contribute ideas, modules etc.

What language would you suggest if php is not the right way to go. I originally intended this project to be browser based so that anyone could play it without having to have a certain spec PC or Mac.

Would it be a better solution to have the matches run if javascript and use php for showing the rest. Any ideas would be really welcome.