Forum Archive

Newbie with problem to understand the difference

Bombastino

In this program i want to develop a Matrix of a Solitär playfield.
I could not find the difference if I want to began at the base line with MatrixFeld[0,0]

[202020202
 020202020
 002020200
 000202000
 000020000]

It gives me an error if j = 0 but not if began at j = 1
For me there is no difference.
WHO could give me help.
Thank you.
Christoph

import numpy as np
def main():

    spielFeld = int(
        input('Länge des Spielfelde')
        )
    nullFeld = 0
    freiesFeld = 1
    belegtesFeld = 2
    maxx=spielFeld 
    maxy= spielFeld // 2 + 1
    Feld = np
    Feld.shape = (maxy, maxx)
    FeldMatrix = np.zeros(Feld.shape)

    j = 0
    '''for j in range(0, maxy):'''
  for i in range(j, maxx-j, 2):
          FeldMatrix [j,i] = freiesFeld
          FeldMatrix [j,i+1] = nullFeld

    j = 1
    for i in range(j, maxx-j, 2):
            FeldMatrix [j,i] = freiesFeld
            FeldMatrix [j,i+1] = nullFeld       
    j = 2
    for i in range(j, maxx-j, 2):
            FeldMatrix [j,i] = freiesFeld
            FeldMatrix [j,i+1] = nullFeld   
    j = 3
    for i in range(j, maxx-j, 2):
            FeldMatrix [j,i] = freiesFeld
            FeldMatrix [j,i+1] = nullFeld       
    j = 4
    for i in range(j, maxx-j, 2):
            FeldMatrix [j,i] = freiesFeld
            FeldMatrix [j,i+1] = nullFeld   


    print(FeldMatrix)


if __name__ == '__main__':
    main()
cvp

@Bombastino It seems that the indentation of these lines is not correct:

for i in range(j, maxx-j, 2):
    FeldMatrix [j,i] = freiesFeld
    FeldMatrix [j,i+1] = nullFeld