-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeatMapData.py
More file actions
64 lines (47 loc) · 1.58 KB
/
HeatMapData.py
File metadata and controls
64 lines (47 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 11 22:43:18 2023
@author: fabian
"""
import random as rd
import numpy
import csv
rd.seed(42)
numPart = 1
pointToHit = numpy.array([4, 3], dtype=int)
NORTH = 1; SOUTH = 2; WEST = 3; EAST = 4
def hitCheck(pointToHit, realPoint):
return numpy.array_equal(pointToHit, realPoint)
def singleStep():
position = numpy.zeros(shape=(2,), dtype=int)
currentStep = rd.randint(1, 4 + 1)
position[1] += numpy.where(currentStep == NORTH, 1, 0)
position[1] -= numpy.where(currentStep == SOUTH, 1, 0)
position[0] += numpy.where(currentStep == EAST, 1, 0)
position[0] -= numpy.where(currentStep == WEST, 1, 0)
return position
def walkTillHit(numPart=1, maxStep=5):
positionsArray = numpy.zeros(shape=(maxStep+1, 2), dtype=int)
hitArray = numpy.zeros(shape=(maxStep+1, 2))
for step in numpy.arange(maxStep):
positionsArray[step+1, ] = positionsArray[step, ] + singleStep()
if hitCheck(pointToHit, positionsArray[step+1, ]):
hitArray[step+1, 0] = True
hitArray[step+1, 1] = step+1
else:
hitArray[step+1, 0] = False
hitArray[step+1, 1] = 0
return hitArray
def writeToCSV(hitArray):
print(hitArray)
headers = ['Treffer', 'Nach Schritten']
filename = "Search_For_Point_4,3_.csv"
with open(filename, 'w') as csvfile:
csvWriter = csv.writer(csvfile)
csvWriter.writerow(headers)
csvWriter.writerows(hitArray)
def main():
writeToCSV(walkTillHit(1, 50000))
if __name__ == "__main__":
main()