Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with cross
#11
Is there any way how to get this defining a fuction ?? Shy
#12
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()
#13
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..) Sick Sick Sick

#14
Sorry for wrong understanding.
Meanwhile I know what "angry man" is .
But this is a very ambitious project for a beginner.
#15
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 ?
#16
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
#17
Why should i split my code into two functions ?
#18
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, y
I did it like this , but this function moves with figures counter-clockwise. I tried to make it in clock direction Big Grin Big Grin Big Grin Thanks for your recent help with spliting functions it helps me really. Cool
#19
Do you have any idea how to make an entrance to the "house" for figure ?
#20
You could extend nextpos-function.
For each position move you have to check for entrance.


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020