I am interested in creating a game bot and was hoping to find someone who could offer some assistance

Started by
1 comment, last by scott8 2 months ago

I need a bot for a mini-game that functions similarly to a Snake game in terms of its mechanics.
A= Pot which is somewhat like a fruit in a snake classic game, but here it keeps moving every 2 seconds in a random place on this grid.
B= The Fruit here is like a snake who keeps moving. All we can do is control and guide it in such a way to hit the pot and make a score.
C= the joystick in the middle is just for a visual representation of the direction of the fruit in the game, which changes direction based on the arrow keys we press.
D= The timing seen on top is a cycle of 15 seconds, which means a fruit has 15 seconds to hit the pot if it doesn't manage to hit the pot in 15 seconds we don't score and a new cycle starts.

The mechanism works as follows:
The fruit begins at the centre of the grid, directly below the joystick, and moves toward a specific position. Using arrow keys (up, down, right, left), we control its movement to ensure it hits the pot within a 15-second time limit. The cycle concludes under three conditions: the 15-second time limit elapses, the fruit successfully hits the pot, or the fruit collides with the grid's walls. In any of these cases, a new cycle begins.

Advertisement

If I understand this correctly, you want an algorithm that will guide the fruit to a moving pot? And you can't move diagonally?

some code you could use in an UpdateFruit() routine:

  1. Calculate the current distance of the the fruit's X and Y coordinates from the pot's X and Y coordinates.
Pot_Distance.x = Fruit_Position.x - Pot_Position.x;
Pot_Distance.y = Fruit_Position.y - Pot_Position.y;

2. Move the fruit in the direction of the shortest distance:

If (std::abs(X_Distance) < std::abs(Y_Distance) )   // could be positive or negative, use abs
	Fruit_Position.x += Step_Size * std::abs(X_Distance) / X_Distance;
else
    Fruit_Position.y += Step_Size * std::abs(Y_Distance) / Y_Distance;

The std::abs(X_Distance) / X_Distance will be +1 if the Pot is to the right of the fruit, -1 if the pot is to the left of the pot.

A more advanced algoithm would consist of calculating how much time it would take to reach the pot's position, then predict the pot's position given it's current direction and the time required. Then repeat using the pot's predicted position. After a few iterations, it should converge.

This topic is closed to new replies.

Advertisement