Die Antwort Art und Weise anders ist, da es zu meinem Problem (Field Of View) ziemlich angepasst ist.
def updatevalues(self,array,elementsCount):
counter =0
R1 =Agent.GetCenterCoords(array.shape)[0]
C1 = array.shape[1]-1
coords = {'R1':R1,'R2':R1,'C1':C1,'C2':C1,'Phase':1}
array[coords['R1'],coords['C1']] = True
while counter<elementsCount:
counter +=2
self.Phases[coords['Phase']](array,coords)
def Phase1(self,array,coords):
'''
Phase 1.
During this phase we start from the max column(C1,C2) and middle Row (R1,R2)
and start moving up and down till
minimum row (R1) , max Row (R2) then we move to phase 2
'''
coords['R1'] -=1
coords['R2'] +=1
array[coords['R1'],coords['C1']] = True
array[coords['R2'],coords['C2']] = True
if coords['R1']==0 or coords['R2'] == array.shape[0]-1:
coords['Phase']=2
def Phase2(self,array,coords):
'''
Phase 2.
During this phase we start from the max column (C1,C2) and Min,Max Rows (R1,R2)
and start changing (C1,C2 to minimum) till
C1,C2 ==0 then we move to phase 3
'''
coords['C1'] -=1
coords['C2'] -=1
array[coords['R1'],coords['C1']] = True
array[coords['R2'],coords['C2']] = True
if coords['C1']==0 or coords['C2'] ==0:
coords['Phase']=3
def Phase3(self,array,coords):
'''
Phase 3.
During this phase we start from the minimum columns (C1,C2) and Min,Max Rows (R1,R2)
and start changing (R1,R2) toward center till R1==R2 then we break (all border got covered)
'''
coords['R1'] +=1
coords['R2'] -=1
array[coords['R1'],coords['C1']] = True
array[coords['R2'],coords['C2']] = True
if coords['R1']==coords['R2']:
coords['Phase']=4
@staticmethod
def GetCenterCoords(shape):
return (shape[0]-1)/2 , (shape[1]-1)/2
die Lösung hängt davon ab, wie viele Werte, die wir wollen, an der Grenze von der max Reihe, mittlere Spalte auf die dann in zwei Richtungen bewegen gleichzeitig beginnen direkt starten ändern. Sorry für die komplexe Lösung, aber wie ich schon sagte @Ophir ist es ziemlich maßgeschneiderte Lösung für mein Problem. (Als ich die Frage stellte, benutzte ich ein sehr allgemeines Forum, um es zu vereinfachen.) hoffe, dass diese anderen eines Tages helfen.
Es ist nicht immer von 1 bis 8, in den meisten Fällen ist es binär (0,1), so dass jede Kombination möglich ist. Ich habe Ihren Code ausprobiert und er wird nicht die Reihenfolge des bereitgestellten Arrays beibehalten. und das Array Ich möchte nicht immer 1 Element auffüllen, manchmal ist es viel mehr als das. – samer226047
sehe meine bearbeitete Antwort –
Dank der Code funktionierte gut. aber ich habe es geschafft, den Code für meinen Fall mit 10^-5-mal im Vergleich zu 10^-3 mit Ihrem Code zu ändern. Danke nochmal. – samer226047