a way of earning more points by finding the length of a route

Asked 1 years ago, Updated 1 years ago, 117 views

Hello. Thank you for your continuous support.

Now I'm making a game like Packman, and I'm making something like AI of enemy characters.
At that time, I could ask for the shortest route to take the item, but I asked because I didn't know how to write the program that I wanted to make efficient without asking for the shortest.

As a prerequisite, as a rule,

  • The winning conditions are based on points, and the items are 5 and 10 points.
  • Each move reduces the '1' cost. Move up, down, left, and right.
  • There's a rock on it because you can't get through.
  • And as a trap, there is a warp that goes from there to somewhere.(Where you flew will be given the value of how long you moved from there.)

The strategy of the program that I want to write on my own is to write the program that gets the most points within 5 costs (for calculation reasons).Please teach me.

The language is C++.
Enemy characters are calculated by making maps on the array.

c++ algorithm c++11 c++-cli

2022-09-30 20:55

1 Answers

No matter what game you play, the idea of implementing AI is basically the same.Explore all the possibilities of every step, calculate the score for each of the possibilities, and choose the highest-scoring step.If it's a Pac-Man-like game, there's a possibility of up, down, left, right, left, right, right, left, right, right, left, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, right, left, right, right, right, left, right, right, right, right,In fact, there are walls, so all four ways won't work, and the branches will be a little less.

If there is a stochastic event such as a random warp, simply calculate the expected value.If you can calculate all your expectations in gambling, you'll find the best solution (although you'll only know that you'll lose if you repeat it).Also, while game conditions vary depending on the player's manipulation, strategies are often studied as minimax method (although this "strategy" may not necessarily agree with everyone in real-world games, it is objectively defined).

However, it is highly questionable whether it is necessary for AI in the game to seek such an optimal solution.Only some games, such as chess and shogi, need to find the best solution.

For example, if an enemy character takes such an optimal strategy in RPG, it becomes a monotonous movement in which every monster simply releases its most powerful skills and magic from the beginning until the MP runs out, and it never becomes an interesting game.Also, AI, which always takes the best solution, is not necessarily the strongest because the player reads the action.If you want to add unexpectedness to the enemy's movements, you have to add randomness to the movements, but this reduces the meaning of calculating the best solution.

In fact, even a simple AI that changes course randomly when you come to a forked road can be interesting depending on the game design, and it looks like a human being is moving it.If you want to make the game harder, it would be easier to adjust the difficulty level by increasing the enemy's HP with RPG, or by increasing the number of enemies with Pac-Man, rather than creating strong AI.

  • Summary: Even if you create the best AI, the game won't be fun even though you worked hard.

If you can't implement game trees in the first place, you should learn how to implement game trees using simple rules.

  • Only one item
  • Move left and right, up to two
  • The map is one-dimensional with a length of 5.No Obstacles
  • Start position 2 (so it doesn't hit the edge of the map)
  • No warp

Current State

var state={
    map: [0,0,0,1,1], //1 has one item
    playerPosition:2
};

as

 var moves=[
    { move: ["L", "L", point:0}, // If you move to the left twice, the item is 0
    { move: ["L", "R", point:0}, // If you go to the left and then to the right, the item is 0
    { move: ["R", "L", point:1} , // Go right and move left to get 1 item
    { move: ["R", "R", point:2} // Move to the right twice to get 2 items
];

Explore all possibilities and calculate the score (this pseudocode is JavaScript). Once moves is calculated, the largest point is the last {move:["R", "R", point:2}, so select the first step "R"."


2022-09-30 20:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.