@ccc Thank you very much!
Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Posts made by amharder
-
RE: Sudoku crashes my ipad!
WARNING: This will crash your pythonista on execution. But if you might know why that would be helpful.
from scene import * import random import numpy as np class game(Scene): def setup(self): self.found = False self.board = list([[0] for i in range(9)] for i in range(9)) for column in range(0,9): for row in range(0,9): run = True while run: x = random.randint(1,9) self.find(column,x,row) if self.found == False: self.board[column][row] = x run = False print(self.board) def find(self,list,arg,orig): n = list o = arg p = orig self.found = False if o not in self.board[n]: for y in range(9): if y != n: if self.board[y][p] == o: self.found = True else: self.found = True run(game())
-
RE: Sudoku crashes my ipad!
Sorry I didn't explain more, it was crashing, and I tried to fix the code, now it doesnt crash, but there are the same numbers horizontal to each other, contrary to rules of sudoku. If you need more info please write back, but if you can help please help!
-
Sudoku crashes my ipad!
Hello everyone, I've been told that the reason for these crashes is how much data is being processed. Here is my code:
import random class game(object): def __init__(self): self.found = False self.board = list([[0] for i in range(9)] for i in range(9)) for column in range(0,9): for row in range(0,9): run = True while run: x = random.randint(1,9) n = column o = x p = row self.found = False if x not in self.board[column]: for y in range(9): self.check = True if y != column: if self.board[y][row] == x: self.check = False else: self.check = False if self.check == True: self.board[column][row] = x run = False print(self.board) game()
What do you think? How can I fix this to make a working sudoku generator. If you also know how to make the 3 by 3 squares, that would help out too. Thank you.
-
Recieving error when deleting data from within a list!
Hello, I am attempting to create sudoku within pythonista, and within the following code I am trying to create the 9x9 space, and place numbers in each square. When I run this, I get the error that whatever x is equal to within the for loop, is not inside of the column in which it has been placed. When I tried to troubleshoot this, I narrowed the issue down to the delete, or del, command used within my code. If I replaced that with a print statement, the code works fine, even though delete has nothing to do with testing to see if x is within its column. My code is below, please help if you can.
import random board = [[],[],[],[],[],[],[],[],[]] for column in range(9): run = True while run: x = random.randint(1,9) if x not in board[column]: board[column].append(x) for y in range(9): if y != column: r = board[column].index(x) if x in board[y]: if r == board[y].index(x): del board[column][r] if len(board[column]) == 9: run = False print(board)
Thank you.
-
Making chess, any tips?
Hello everyone!
I need your help with a chess game that I am making. I think that with enough time and unpythonic programming, I can make this game possible, although I would like to find a better way.
Here is my main code:from scene import * from Chessboard import Chessboardd class game(Scene): def __init__(self): Scene.__init__(self) def setup(self): self.r = Chessboardd(self.bounds.center(), Size(700, 700)) self.kingw = LabelNode(u"\N{WHITE CHESS KING}", font=('Helvetica', 100), position=(468 + 88,75), parent=self) def draw(self): background(0,0,0) self.r.draw() def touch_ended(self, Touch): if Touch.location.x < self.kingw.frame.x and Touch.location.x > self.kingw.frame.x - 88 and Touch.location.y < self.kingw.frame.y + 90 and Touch.location.y > self.kingw.frame.y: self.kingw.run_action(Action.move_by(-88,0)) if Touch.location.x > self.kingw.frame.x + 70 and Touch.location.x < self.kingw.frame.x + 50 + 125 and Touch.location.y < self.kingw.frame.y + 90 and Touch.location.y > self.kingw.frame.y: self.kingw.run_action(Action.move_by(88,0)) if Touch.location.y < self.kingw.frame.y and Touch.location.y > self.kingw.frame.y - 88 and Touch.location.x > self.kingw.frame.x and Touch.location.x < self.kingw.frame.x + 88: self.kingw.run_action(Action.move_by(0,-88)) if Touch.location.y > self.kingw.frame.y + 100 and Touch.location.y < self.kingw.frame.y + 100 + 110 and Touch.location.x > self.kingw.frame.x and Touch.location.x < self.kingw.frame.x + 88: self.kingw.run_action(Action.move_by(0,88)) if Touch.location.x < self.kingw.frame.x and Touch.location.x > self.kingw.frame.x - 90 and Touch.location.y > self.kingw.frame.y + 88 and Touch.location.y < self.kingw.frame.y + 88 + 88: self.kingw.run_action(Action.move_by(-88,88)) if Touch.location.x > self.kingw.frame.x + 88 and Touch.location.x < self.kingw.frame.x + 88 + 88 and Touch.location.y > self.kingw.frame.y + 88 and Touch.location.y < self.kingw.frame.y + 88 + 88: self.kingw.run_action(Action.move_by(88,88)) if Touch.location.x < self.kingw.frame.x and Touch.location.x > self.kingw.frame.x - 88 and Touch.location.y < self.kingw.frame.y and Touch.location.y > self.kingw.frame.y - 88: self.kingw.run_action(Action.move_by(-88,-88)) if Touch.location.x > self.kingw.frame.x + 88 and Touch.location.x < self.kingw.frame.x + 88 + 88 and Touch.location.y < self.kingw.frame.y and Touch.location.y > self.kingw.frame.y - 88: self.kingw.run_action(Action.move_by(88,-88)) run(game())
Now, I realize that I could put each chess piece in different classes, and give them the ability to move in their seperate fashion, although I do not know how to do that, because if I created for example, a class named King, and I assigned a king to that with parameter color being black or white that would choose the color of the king, could I simply put a move function within King that allows them to move normally? When I try this, I cannot figure out a simple, or any way to do it. Also, here is my code for the chessboard module:
from scene import * class Chessboardd: def __init__(self, position, size): self.position = position self.size = size def draw(self): fill(1,0,0) for x in range(8): for y in range(8): black = (x + y) % 2 == 0 # true if checkerboard square should be black if black: fill(.66, .46, .25) else: fill(1.0, .7, .38) rect(self.position.x + self.size.w*(x/8.0) - self.size.w/2.0, self.position.y + self.size.h*(y/8.0) - self.size.h/2.0, self.size.w/8.0, self.size.h/8.0)
So I guess my question is, how can I give seperate chess pieces their own individual set of moves, because with the method I am using, all pieces could only move in the spaces surrounding. Please help!
-
Moving a node help!
I'm sorry I have so many questions lol, I am sort of new to programming, but here is my question. When you use Action to move a node, for example to a Touch.location, there are two drawings of it on the screen! One in the new position, and one in the old position, here is my code:
from scene import * class game(Scene): def __init__(self): Scene.__init__(self) def setup(self): pass def draw(self): background(0,0,0) self.test = LabelNode("memes", font=('Helvetic a', 100), position= (500,500), parent=self) def touch_ended(self, Touch): self.test.run_action(Action.move_to (Touch.location.x,Touch.location.y)) run(game())
This works, but as I said before there is a node in the old location of the node, even after it is moved. Please help!
-
RE: How to use a unicode character as a movable object in scene?
@abcabc oh lol, oops. Thank you for your help!!
-
RE: How to use a unicode character as a movable object in scene?
@abcabc I'm sorry, I understand what you mean, but I just can't figure it out. Here is my code for a label node:
from scene import * class test(Scene): def setup(self): self.background_color = 'beige' self.test = LabelNode(unichr(9812), 500, 500) run(test())
And when I run it, I get the strangest error, typeerror expect a texture or image. Please help!
-
How to use a unicode character as a movable object in scene?
I am trying to make chess, I can draw the image of the unicode king chess piece with this code:
from scene import * class example(Scene): def draw(self): image(render_text(str(unichr(9812)), font_size = 80)[0], examplex, exampley)
When I run this, it draws the king chess piece at the inputted x and y, although I am trying to create a touch event where the king moves to where the player taps, that is what I need and I can do the logic part with testing if it is a legal move, although, how can I move the king without re-running the draw function. Please help!
-
Scene_drawing help!
I am trying to use scene_drawing to create a chessboard, and it is not going well at all, no matter what coordinates I put in for each square, it outlines the entire scene, please help! First post, should I enter my code or should I not?