Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 495 496 [497] 498 499 ... 796

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

Sergarr

  • Bay Watcher
  • (9) airheaded baka (9)
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7440 on: May 22, 2015, 02:13:46 pm »

Oh boy, I remember when I've accidentally learned how python works by trying to add proper multiplayer to Severance: Blade of Darkness.

I for a long time had no idea what was going on until I've enabled a console and then saw that the latest version of the game gave dozens of errors messages that were disabling like half of functions and doing crazy shit.

There also was a function that was literally called "FastChapuzaSolution". I at first thought that it was some "exception" type function, until I've realized that the "normal" function wasn't actually working at all.

Fun times~
Logged
._.

AlleeCat

  • Bay Watcher
  • Black, the beast, descends from shadows...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7441 on: May 22, 2015, 03:25:08 pm »

Have each room have an extra flag, and have "scavenge" run a function that flips the flag and gives the item(s) in the room?
I didn't think of that! Thanks

Willfor

  • Bay Watcher
  • The great magmaman adventurer. I do it for hugs.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7442 on: May 22, 2015, 05:19:16 pm »

I think the entire library has some kind of internal structure, but it appears to be really inconsistent.
I fixed this quote to better reflect the realities of libtcod. Just today I encountered yet another inconsistency between libtcod's python wrapper and it's documentation ... and then another in its interface with its C roots that would have been better served by copy/paste.

I assume the C# libtcod is still sort of unmaintained? (because C# is best)
Yes. It's been unmaintained for about ... sixish years now?
Logged
In the wells of livestock vans with shells and garden sands /
Iron mixed with oxygen as per the laws of chemistry and chance /
A shape was roughly human, it was only roughly human /
Apparition eyes / Apparition eyes / Knock, apparition, knock / Eyes, apparition eyes /

bahihs

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7443 on: May 22, 2015, 06:44:44 pm »

Alright so I now have usable maps, but have to re-write my pathfinding code.

Again, I'm using libtcod with Python. I want each tile on the map to have a specific movement cost  (which ranges from 1 to 4) based on its terrain. Then whenever I hover my mouse over a unit, it should display all the tiles that unit can move to (based on the unit's hard-coded range).

I can't figure out how to use the pathfinding functions that come with the module for this. I can easily show all tiles in a given range, and just as easily account for impassible tiles (other units and mountains).

From what I can tell this is a two part problem:

1. Assign a terrain cost to each tile on the map by iterating over the entire map, maybe during map generation(I think I need to create a "Tile" class for this)
2. Have the pathfinding function (I'm using Djtskra) account for the terrain cost when it calculates the paths. I think I have to use the "dijkstra_new_using_function" function and create another function which calculates the cost, but I don't know what this function should look like nor how it should work.

Any help would be very appreciated
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7444 on: May 22, 2015, 08:02:06 pm »

When I hit this problem while doing Chartered Waters I made my own A* implementation with terrain costs and hookers... probably impractical for Python because can't optimize as essily >.>
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7445 on: May 23, 2015, 04:34:55 am »

It's not "optimize as easily". Python is just slow compared to c++. It has zero to do with your optimization abilities. The same exact algorithm will almost always be faster in c++.

The exceptions will be when the whole thing is one native procedure that you call in Python as a single command, and in that case it was itself written in c++. But in those cases it will usually be possible to write a faster custom c++ function that does the same thing. That's because library code is written to perform every possible task, whereas if you only need one specific task done, then a hand-written function can be much more compactly written, and can be "inlined" which means it's directly compiled into your program instead of being a separate function.
« Last Edit: May 23, 2015, 04:42:49 am by Reelya »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7446 on: May 23, 2015, 06:37:36 am »

You didn't refute my point...

I didn't say that C++ is slower than Python. I said that it's harder to optimize things in Python than it is in C++. Mainly because it hides a lot of memory thingies from you.

Still possible to get algorithmic optimization, and this applies to any language. :v
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7447 on: May 23, 2015, 01:58:30 pm »

Uploaded 2 more graphics tutorial code things here, tut3 and tut4: https://github.com/jalway
As always, feedback and questions more than welcome, as it will help refine the code for potential use by students. These still need a bit more polish, but eh, good enough for now.

tut3 begins using data from outside the shaders in the form of textures; it uses these to draw a heightmap.
tut4 expands upon these themes to draw a 3D mesh from a .obj file using buffer textures.
Logged

AlleeCat

  • Bay Watcher
  • Black, the beast, descends from shadows...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7448 on: May 24, 2015, 05:35:54 pm »

More Inform problems.

Code: [Select]
"A man sits slumped against a wall, visibly [if wounded crewman is unconscious]unconscious[otherwise]conscious[end if],

Code: [Select]
the door to the north has a large display over it saying 'BRIDGE' in big [if bridge door is unlocked]green[otherwise]red[end if] letters.Both of these are from descriptions. Both of them use values that are defined in the source code. The difference is, the second one works, while the first one does not. I've tested them individually and the only one that brings up errors is the first one. Why is that?

I can't find any real reasons why Inform would tell me I'm not using an if statement right, unless both of them were wrong, but one of them isn't.

CLARIFICATION:
The specific error is telling me that it doesn't recognize the phrase "if wounded crewman is unconscious."
« Last Edit: May 24, 2015, 06:03:53 pm by AlleeCat »
Logged

P(ony)SI

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7449 on: May 24, 2015, 06:37:34 pm »

CLARIFICATION:
The specific error is telling me that it doesn't recognize the phrase "if wounded crewman is unconscious."
While I haven't used Inform, it seems like your if-else syntax is correct. Are you absolutely sure that you have "wounded crewman" and "unconscious" spelled correctly in your source code?
Logged

AlleeCat

  • Bay Watcher
  • Black, the beast, descends from shadows...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7450 on: May 24, 2015, 07:09:25 pm »

Quote from: ifMUD
[I7] AlleeCat says, "well... I feel silly now"
[I7] Hunter asks, "Did you figure something out?"
[I7] AlleeCat says, "Turns out the problem wasn't even there. If I had just hit the arrow next to the error I would have found that incomplete piece of code I'd left and forgot about..."
[I7] AlleeCat says, ""Check examining the wounded crewman: If the wounded crewman is unconscious:" then nothing after"
[I7] vaporware says, "Ah, tricky."
[I7] AlleeCat says, "It also probably should have been apparent because of the added 'the' but I also got hung up on what turned out to be a typo for a good 30 minutes in the same code"

Sergarr

  • Bay Watcher
  • (9) airheaded baka (9)
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7451 on: May 26, 2015, 07:31:11 am »

What would be the best method for finding which point from an array is the closest to a chosen point in an N dimension space (where N is a large number), if there are a lot of points and I can't afford to simply loop through all of them?
Logged
._.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7452 on: May 26, 2015, 07:40:26 am »

By using a quadtree (2d) or octree (3d) instead of an array. :D

Or some other spatial data structure...
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7453 on: May 26, 2015, 08:31:54 am »

Is there an up-to-date llvm tutorial anywhere?
Not only is the tutorial in the docs (the one for version 3.7, which isn't the standard one in Debian, isn't any different from this version) a horrible mess where the location of added code becomes only clear when scrolling to the end of the chapter and looking in the complete code listing and not only is everything put into one monolithic file but the supplied code from Chapter 4 onwards doesn't even compile.
Logged
Taste my Paci-Fist

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7454 on: May 26, 2015, 09:18:55 am »

What would be the best method for finding which point from an array is the closest to a chosen point in an N dimension space (where N is a large number), if there are a lot of points and I can't afford to simply loop through all of them?
High-dimensional spaces seem to have the unfortunate tendency to cause pretty much linear runtime in any sort of exact closest-point algorithm (including space partitioning algorithms such as quad- and octrees). If you really want to get any sort of sublinear behavior, you might want to look into getting approximate solutions instead of exact ones.
Logged
Pages: 1 ... 495 496 [497] 498 499 ... 796