Nov-18-2017, 05:55 PM
Is there any way how to get this defining a fuction ??

help with cross
|
Nov-18-2017, 05:55 PM
Is there any way how to get this defining a fuction ??
![]()
Nov-18-2017, 06:04 PM
I am a little bit disappointed about your wish.
You should code it yourself. #!/usr/bin/python3 def square(): matrix = [ " *** " , " *d* " , " *d* " , "****d****" , "*dddxddd*" , "****d****" , " *d* " , " *d* " , " *** " ] for s in matrix: print(s) square()
I wasnt thinking like that my question was is there any possible way how to do it like fuction and i can handle it f.ex.(changing position of A or B of course i knew how to change it to fuction... u know im lost in this project..)
![]() ![]() ![]()
Sorry for wrong understanding.
Meanwhile I know what "angry man" is . But this is a very ambitious project for a beginner.
Nov-22-2017, 07:14 PM
Hi finally i did this gaming grid
def sachovnica(n): doska=[[' 'for i in range(n) ] for j in range(n)] npul=n//2 for i in range(n): doska[npul-1][i]='*';doska[npul+1][i]='*' doska[i][npul-1]='*';doska[i][npul+1]='*' doska[npul][0]='*';doska[npul][n-1]='*' doska[0][npul]='*';doska[n-1][npul]='*' for i in range(1,npul): doska[npul][i]="D";doska[npul][n-i-1]="D" doska[i][npul]="D";doska[n-i-1][npul]="D" doska[npul][npul]="X" doska[n-1][npul-1]='A' for n in doska: print (' '.join(n))but now i dont know how to make a step with figure. Dont you know how to do this ?
First you have to split your function in two functions.
One for creation the board, the second for displaying. import pprint doska = [ ] def create_sachovnica(n): global doska doska=[[' 'for i in range(n) ] for j in range(n)] npul=n//2 for i in range(n): doska[npul-1][i]='*';doska[npul+1][i]='*' doska[i][npul-1]='*';doska[i][npul+1]='*' doska[npul][0]='*';doska[npul][n-1]='*' doska[0][npul]='*';doska[n-1][npul]='*' for i in range(1,npul): doska[npul][i]="D";doska[npul][n-i-1]="D" doska[i][npul]="D";doska[n-i-1][npul]="D" doska[npul][npul]="X" doska[n-1][npul-1]='A' def print_sachovnica(n): for n in doska: print (' '.join(n)) print() # main create_sachovnica(9) print_sachovnica(9)Either you work a lot with global variables for board, positions for 4 players, ... or you do it with classes (this is the better and easier way). You could study this games: http://inventwithpython.com/chapter10.html http://www.practicepython.org/exercise/2...-game.html
Nov-24-2017, 02:13 PM
Why should i split my code into two functions ?
Nov-24-2017, 03:17 PM
def nextpos(doska, x, y): size = len(doska) if x < size // 2: if y > 0 and doska[y-1][x] == '*': return x, y-1 else: if y < size-1 and doska[y+1][x] == '*': return x, y+1 if y < size // 2: if x < size-1 and doska[y][x+1] == '*': return x+1, y else: if x > 0 and doska[y][x-1] == '*': return x-1, y return x, yI did it like this , but this function moves with figures counter-clockwise. I tried to make it in clock direction ![]() ![]() ![]() ![]()
Nov-25-2017, 02:44 PM
Do you have any idea how to make an entrance to the "house" for figure ?
Nov-25-2017, 03:10 PM
You could extend nextpos-function.
For each position move you have to check for entrance. |
|