omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. amharder

    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.


    • Profile
    • Following 0
    • Followers 0
    • Topics 6
    • Posts 14
    • Best 0
    • Controversial 0
    • Groups 0

    amharder

    @amharder

    0
    Reputation
    959
    Profile views
    14
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    amharder Unfollow Follow

    Latest posts made by amharder

    • RE: Sudoku crashes my ipad!

      @ccc Thank you very much!

      posted in Pythonista
      amharder
      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())
      				
      	
      
      posted in Pythonista
      amharder
      amharder
    • 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!

      posted in Pythonista
      amharder
      amharder
    • 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.

      posted in Pythonista
      amharder
      amharder
    • 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.

      posted in Pythonista
      amharder
      amharder
    • RE: Making chess, any tips?

      @brumm @ccc Thank you!

      posted in Pythonista
      amharder
      amharder
    • 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!

      posted in Pythonista
      amharder
      amharder
    • RE: Moving a node help!

      @omz omg lol it worked! Thank you so much omz!

      posted in Pythonista
      amharder
      amharder
    • RE: Moving a node help!

      @omz Will that fix the problem?

      posted in Pythonista
      amharder
      amharder
    • 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!

      posted in Pythonista
      amharder
      amharder