Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 641 642 [643] 644 645 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 887815 times)

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9630 on: May 27, 2016, 01:29:09 am »

Yeah, I already accepted the limitation of convex polygons. I'm just rejecting any input that isn't convex. It's really confusing to visualize how to determine which vertices from polygon A should be placed between which ones from polygon B, and how I should be altering the coordinates to account for the new vertices I shoved in between.
Unless I horribly, horribly misunderstood what a Minkowski sum is, or what your task is, you don't need to put the angles in the same list. You just need to add the vertices.
Well you're not wrong about what a Minkowski sum is, what you haven't looked into is the linear time algorithm for generating the Minkowski set for two convex polygons, which is what Gatleos is trying to code.

@Gatleos: having thought about it, what I think the algorithm is doing is you take each edge of both polygons, then you always pick the next one with a slope/angle which is the closest possible one to the last one, but in a clockwise direction. Then append that onto your line, and the end result is that you get back where you started, with the completed Minkowski polygon for two convex polys. Each edge from your starting collection should be used only once in the final output. Just look at the next segment from each poly, and pick the one that's closest to the current segment's angle. Once you've exhausted all points, you have your poly. To get the offsets, just find any point where segments from each poly meet, then add their offsets, then you can propagate these around the edges.
« Last Edit: May 27, 2016, 01:56:37 am by Reelya »
Logged

Shadowlord

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9631 on: May 27, 2016, 01:59:00 am »

So when you said some of your polygons were clockwise and some were anti-spinward counterclockwise, I'm wondering: Is there a reason for that?
Logged
<Dakkan> There are human laws, and then there are laws of physics. I don't bike in the city because of the second.
Dwarf Fortress Map Archive

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9632 on: May 27, 2016, 02:54:10 am »

That's just a data entry issue. You can do the cross-product check (in 3d space) to know to wind the polys the other way if needed.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9633 on: May 27, 2016, 10:12:18 am »

You messed up the comparison in said for loop.
Yeah whoops. Not sure how I didn't notice that... I just ended up switching it out for forEach loops. Still getting used to javascript.

Code: [Select]
for(var i = 0; i++; i >= pipes.length - 1)
Just looks wrong to me. For loops in JavaScript aren't any different to in c/c++ (except for "var"). The comparison is wrong, and it's in the wrong spot.
The comparison is wrong, yeah, but how is it in the wrong spot?
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9634 on: May 27, 2016, 10:15:04 am »

for(initializing;check this condition;what happens at the end)
You switched up the last two.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9635 on: May 27, 2016, 10:15:19 am »

Here's how to fix it:

Code: [Select]
for(var i = 0; i < pipes.length; ++i)
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9636 on: May 27, 2016, 10:26:29 am »

Eh, whoops. Haven't coded in a while >.< Already using forEach() anyway. (Still thanks for reminding me of the correct syntax though)

Now facing a more confounding problem, namely, this:



E:

the solution is pretty obvious again, i was using absolute coordinates in a function that called for (x, y, width, height) (but i wanted to share the bug anyway because it looks funny)
« Last Edit: May 27, 2016, 10:41:06 am by miauw62 »
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Avis-Mergulus

  • Bay Watcher
  • This adorable animal can't work.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9637 on: May 27, 2016, 10:46:52 am »

Spoiler (click to show/hide)

Your problem here is that, just as the traceback days, tuples don't support item assignment, or anything else for that matter. They're not modifiable. So maybe just use a list?
Logged
“See this Payam!” cried the gods, “He deceives us! He cruelly abuses our lustful hearts!”

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #9638 on: May 27, 2016, 07:08:32 pm »

So when you said some of your polygons were clockwise and some were anti-spinward counterclockwise, I'm wondering: Is there a reason for that?

Yeah, it's a data-entry thing. These polygons are data imported from Tiled and used for collision mapping. I'm getting the Minkowski Sum of an (arbitrarily-sized) AABB and a completely arbitrary polygon pulled from the collision map, so that I can perform predictive collision testing.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9639 on: May 27, 2016, 11:13:07 pm »

Your problem here is that, just as the traceback days, tuples don't support item assignment, or anything else for that matter. They're not modifiable. So maybe just use a list?
I ended up just leaving the dictionary unaltered and adding each found name to a set, which I could then check names against for membership without worrying about tuples. Sets use hashing, so that part should be efficient. It looks something like this now:
Code: (Python) [Select]
found = []
not_found = []
intersect = set()
for tuple in table['Key'][1]:
if tuple[1] in names:
found.append(tuple)
intersect.add(tuple[1])
else:
not_found.append(tuple)
for name in names:
if name not in intersect:
#name exists only in names
for tuple in found:
#tuples with name in names
for tuple in not_found:
#remaining tuples
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9640 on: May 28, 2016, 12:32:19 am »

I don't know what you're doing with that code but would something like this help?

Code: [Select]
found = filter(lambda x: x[1] in names, table['key'][1])
not_found = set(table['key'][1]).difference(found)
Logged

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9641 on: May 28, 2016, 04:37:02 am »

I don't know what you're doing with that code but would something like this help?

Code: [Select]
found = filter(lambda x: x[1] in names, table['key'][1])
not_found = set(table['key'][1]).difference(found)
That definitely looks better. I'll have to see what I can do with it. It's for this (down in the output_merge function.)
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

Elephant Parade

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9642 on: May 29, 2016, 07:46:10 pm »

Working on a Python script for a number-heavy forum game I'm planning to run. It crashes, though, and I can't quite figure out why; any help would be appreciated!

Code: (getstats.py) [Select]
### IMPORTS ###

#currently none

### FUNCTIONS ###

def getstats(list):
    HPF = int(list[1] * (list[0] + 5))
    SPF = int(list[2] * (list[0] + 5))
    ATKF = int(list[3] * (list[0] + 5))
    DEFF = int(list[4] * (list[0] + 5))
    SPAF = int(list[5] * (list[0] + 5))
    SPDF = int(list[6] * (list[0] + 5))
    SPEF = int(list[7] * (list[0] + 5))

    print("HP: " + str(HPF))
    print("SP: " + str(SPF))
    print("ATK: " + str(ATKF))
    print("DEF: " + str(DEFF))
    print("SPA: " + str(SPAF))
    print("SPD: " + str(SPDF))
    print("SPE: " + str(SPEF))

### OTHER DEFINITIONS ###

loop = 1 #this is what makes the loop work

### THE LOOP ###

while loop != 0:

    Name = str(input("NAME: "))
    info = list(input("LV, HP, SP, ATK, DEF, SPA, SPD, SPE: "))
    print()
    print(Name)
    getstats(list)   
    print()

Code: [Select]
Traceback (most recent call last):
  File "C:/Users/.../stats-list.py", line 36, in <module>
    getstats(list)
  File "C:/Users/.../stats-list.py", line 8, in getstats
    HPF = int(list[1] * (list[0] + 5))
TypeError: 'type' object is not subscriptable

The old version didn't use a list; instead, you had to type bases in one at a time. That was dumb, so I changed it to accept a list, but I apparently messed it up somehow?

That, or I'm entering the list wrong. I looked it up online, and (if I read correctly) you need to enter integers one at a time, each separated from the last by a single space. Is that correct?
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9643 on: May 29, 2016, 07:53:09 pm »

Which forum game?
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Elephant Parade

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9644 on: May 29, 2016, 08:02:43 pm »

Which forum game?
Quote from: me
Working on a Python script for a number-heavy forum game I'm planning to run.
It doesn't exist have a thread yet, but it's going to be a tile-based Pokemon strategy game; it draws pretty heavily from FEF (and Pokemon, obviously), but it should still be unique enough to be its own thing.

edit: fixed silly phrasing
« Last Edit: May 29, 2016, 08:05:07 pm by Elephant Parade »
Logged
Pages: 1 ... 641 642 [643] 644 645 ... 796