0

so i am currently making a pacman game and need to make a function of some sort that can give 4 outputs to decide wether the ghost should go up down left or right in order to chase the player

 [0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0]
 [0 2 0 0 0 1 0 0 0 1 1 0 1 0 1 0 0 0 1 0]
 [0 1 0 0 0 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0]
 [0 1 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 1 0]
 [0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0]
 [0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0]
 [1 1 1 1 1 1 0 3 1 1 1 1 1 0 1 1 1 1 1 1]
 [0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0]
 [0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0]
 [0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 1 0 0 1 0]
 [0 1 0 0 1 0 1 0 1 1 1 1 0 1 0 1 0 0 1 0]
 [0 1 0 0 1 0 1 0 0 0 0 1 0 1 0 1 0 0 1 0]
 [0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0]
 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]

i currently have this array where 1 is a wall 0 is free space to move into 2 is the players position and 3 is the ghost position and i only need it to determine the first movement it should take as it will re run the function when the player next moves one tile and i was just wondering if anyone was able to provide a possible solution as i am very stuck. also diagonal movement is not aloud. thank you

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
J.Rimmer
  • 27
  • 6

1 Answers1

0

Also u need a lot of functions and scopes - checking points, collisions, implementing winning, losing.

Imo u need function - generateBoard(), which fulfill that conditions

  1. Make walls in x-axis and y-axis:

https://www.w3resource.com/python-exercises/numpy/python-numpy-exercise-8.php https://gist.github.com/blaylockbk/a70537b41050d1d761ab6c5ab6e4bd43

import numpy as np
x = np.ones((3,3))
print("Original array:")
print(x)
print("0 on the border and 1 inside in the array")
x = np.pad(x, pad_width=1, mode='constant', constant_values=0)
print(x)

2.Generate enemies

3.Generate pacman (randomize point, but can't be on 1, 2, 0 - need validation here - and also the distance between 3 (pacman) and 2(enemy) should be +2.


As mentioned - that Algorithms find the shortest path from point A to point B

of shortest paths between all pairs of vertices. 

So using that algorithtms is possible to create the most effective path from pacman (2) to generated feed (x)

Floyd-Warshall algorithm: get the shortest paths


To the precise - to block diagonal movement: You need to block:

  • [-1,-1] - left down corner,
  • [+1,+1] - right up corner,
  • [-1,+1] - left up corner,
  • [+1,-1] - right down corner,

from initial pacman and enemy position - I suggest it can be separate class - maybe from some abstract class

Piotr Żak
  • 2,046
  • 5
  • 18
  • 30