Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

soccer game

nathanconnathancon Posts: 7Member
any ideas on how to create a soccer game using java where it is a penalty shootout. i particually want the artificial intelligence for the goalkeeper which is my main priority

Comments

  • IDKIDK Posts: 1,784Member
    : any ideas on how to create a soccer game using java where it is a
    : penalty shootout. i particually want the artificial intelligence for
    : the goalkeeper which is my main priority
    :

    Start with the first thing. Design the engine, the grafix and the ui.
    Then you make an interface to your engine. Then you make your ai work with that interface.

    Neural networks excell in this situtation. (with reinforced learning, if needed).
    Or maybe a genetic algorithm,
    or maybe both...
  • nathanconnathancon Posts: 7Member
    yes but what type of source code is needed
  • zibadianzibadian Posts: 6,349Member
    : yes but what type of source code is needed
    :
    Before writing any code, you'll need to think about several things first. Some of those are:
    - is the game real-time or turn-based?
    - what are the characteristics of the players on the field?
    - is the game multithreaded or single threaded? If multithreaded, which threads do I need?
    - is the field completely visible on the screen or is it side- or up/down scrolling; or perhaps 3D?
    - is the game played by mouse clicks, keyboard or both?
    - etc.

    The answers to these questions will determine the code. For example: a single threaded, turn-based game code has this as basis:
    [code]
    while (playingtime < 90 minutes) {
    for (int playerIndex = 0; playerIndex < 22; playerIndex++) {
    players[playerIndex].move();
    ball.update();
    field.update();
    }
    }
    [/code]
    A real-time, 2-threaded game code has these two htreads:
    [code]
    public void run() {
    screenThread.start();
    while (playingtime < 90 minutes) {
    for (int playerIndex = 0; playerIndex < 22; playerIndex++) {
    if (playerIndex == activePlayer) {
    players[playerIndex].move(getUserInput());
    } else {
    players[playerIndex].move(getAIInput());
    }
    ball.update();
    }
    }
    screenThread.terminated = true;
    }
    [/code]
    [code]
    public void run() {
    while (!screenThread.terminated) {
    field.update();
    }
    }
    [/code]
    As you can imagine, a 3 or more multithreaded engine becomes increasingly difficult to time and needs more and more synchronization.
    As you can see above I placed the players in an array of Player objects. These objects can hold the physical characteristics of the players, the appearance on the field, depending on other choices: the chance of making a successful pass, a successful goal, running speed, stability, etc.
    The code of for a soccer game engine (minus the AI) can quickly increase to thousands of lines. As you can see the question of "what type of source code is needed" is very hard to answer, because it depends on a whole lot of factors and the precise specification of the game itself.
  • nathanconnathancon Posts: 7Member
    so is that the artificial intelligence


  • IDKIDK Posts: 1,784Member
    : so is that the artificial intelligence
    :

    No, as he said, it's the game.
  • nathanconnathancon Posts: 7Member
    so how do i obtain the artificial intelligence
  • IDKIDK Posts: 1,784Member
    : so how do i obtain the artificial intelligence
    :

    I explained just that in my previus post.
  • nathanconnathancon Posts: 7Member
    any sort of examples on the sourcecode for the ai
  • zibadianzibadian Posts: 6,349Member
    : any sort of examples on the sourcecode for the ai
    :
    A very simple AI (non-learning) for a goal-keeper would be: "Stay on the same line as the ball". In code:
    [code]
    if (ball.x < this.x) this.moveLeft();
    else if (ball.x > this.x) this.moveRight();
    [/code]
    A more intricate AI would also keep an eye on other players and calculate the chances of certain actions and predict where the ball will end up based on those actions. Then the goal-keeper will move to the location with the highest chance of the ball ending up.
    An even more complex AI would also instruct defenders to move to intercept the actions with the next highest chances, while not leaving their designated opponent.
    With even more mathematics defenders can move to open up one or more defenders to intercept the ball itself and make a counter-attack.
    A learning AI will need to have a metalanguage to describe various attacks and store all previous attack patterns and optimalize the defence against that pattern. For this kind of coding there is no simple short example to give, because of its complexity and it's size (at least several 100,000 lines if not several 1,000,000).
Sign In or Register to comment.