Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 438 439 [440] 441 442 ... 796

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

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6585 on: November 10, 2014, 03:50:37 am »

And there are good reasons to use the latter sometimes. Of course, I'm pretty sure they want you to use the former whenever the latter isn't necessary.

Python programmers are crazy about standards, thus the whitespace.

optimumtact

  • Bay Watcher
  • I even have sheep
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6586 on: November 10, 2014, 03:53:42 am »

And there are good reasons to use the latter sometimes. Of course, I'm pretty sure they want you to use the former whenever the latter isn't necessary.

Python programmers are crazy about standards, thus the whitespace.
Also generally in most cases for the second one, the enumerate method is more clean and useful
Code: [Select]
for index, val in enumerate(list):
Logged
alternately, I could just take some LSD or something...

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6587 on: November 10, 2014, 04:13:19 am »

I never knew enumerate() was a thing... the only downside is that tuples are immutable :c
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

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6588 on: November 10, 2014, 04:14:53 am »

Yeah, I've been writing it with
Code: [Select]
item = list[i]I would have been getting a lot of errors if I hadn't been doing that.

"range(len(list))" has an advantage because you know what position in the list you're at without having to use .index().  On the other hand if you don't need to know that then you're asking the computer to do a few extra steps, and wasting some time and space to write it all out.

Either way I haven't been doing it on purpose so it was still a weird moment of realization.  Doesn't top the moment where I realized that:
Code: [Select]
class example():
    def __init__(self,num):
        self.num = num

a = example(1)
b = a
a.num += 5
print b.num
will spit out "6".  I thought copying was the default behavior.  I did not yet realize that Python loves setting things as pointers to other things, and I got suprisingly far without realizing that.  Just a moment in Newb Learning to Program, I guess.
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6589 on: November 10, 2014, 04:54:17 am »

will spit out "6".  I thought copying was the default behavior.  I did not yet realize that Python loves setting things as pointers to other things, and I got suprisingly far without realizing that.  Just a moment in Newb Learning to Program, I guess.

Many scripting and Java-esque languages work like that. It takes a bit to get used to (as it doesn't work like ints and floats etc) but it becomes second nature. You just have to make sure that you are fully aware of what that other variable is going to be doing and the consequences (if its reading, the object state might change since it was assigned, if its writing, it could be affecting other things too etc).
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6590 on: November 10, 2014, 09:07:38 pm »

that's why class.copy(class) is such a wonderful thing to add to everything.

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6591 on: November 11, 2014, 04:12:02 am »

This has been driving me insane lately. Bear with me here with a bit of math.

Say we have a discrete sequence x[n] of length N>0. Right, so the next steps are a bit of Fourier shenanigans.

Define:


And calculate


Looks simple enough, right? Well Matlab is throwing some weird nonsense at me.
Specifically:
Code: [Select]
c = zeros(N,1);
for k=0:N-1
    for m = 0:N-1
        c(k+1) = c(k+1) + x(m+1)*exp(-1j*2*pi*k*m/N)/(2*N);
    end
end

x3 = zeros(N,1);
for n=0:N-1
    for k = 0:N-1
        x3(n+1) = x3(n+1) + c(k+1)*exp(1j*2*pi*n*k/N) + ...
            conj(c(k+1))*exp(-1j*2*pi*n*k/N);
    end
end
seems to do fine, the maximum difference is on the order of 10-13 which I chalk up to floating point errors. In fact, c is pretty much the same as fft(x)/(2*N) barring some floating point errors.

On the other hand,
Code: [Select]
c2 = zeros(N,1);
for k=0:N-1
    c2(k+1) = x'*exp(-1j*2*pi*k*[0:N-1]'/N)/(2*N);
end
x4 = zeros(N,1);
for n=0:N-1
    x4(n+1) = c2'*exp(1j*2*pi*n*[0:N-1]'/N) + ...
        conj(c2)'*exp(-1j*2*pi*n*[0:N-1]'/N);
end
I was thinking I could speed up the process by exploiting vectors. However, even though c2 is the same as c barring floating point errors again, the inverse transform is nowhere near the original sequence. Even more strangely, changing the sign of the exponents in the inverse transform gives the correct answer for some reason.

What am I missing here?
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6592 on: November 11, 2014, 04:23:44 am »

And there are good reasons to use the latter sometimes. Of course, I'm pretty sure they want you to use the former whenever the latter isn't necessary.

Python programmers are crazy about standards, thus the whitespace.
Also generally in most cases for the second one, the enumerate method is more clean and useful
Code: [Select]
for index, val in enumerate(list):
Heeeey I know you, I see you on the tgs issue tracker sometimes :V
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.

Sergius

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6593 on: November 11, 2014, 03:29:42 pm »

I'm about to start making a pseudo-ASCII Oubliette-style RPG, and I've been reading about Entity Systems, which I find make a quite compelling case vs using straight OO programming.

Anyone has used that? Right now I'm having trouble figuring out exactly what Entities are supposed to be.
- Game "tokens", as in, just characters?
- Everything including levels, regions, rooms?

There are some clear hierarchies of objects in this game: there are Regions/Areas (ex: The Forest), which contain Locations (ex: Wizard's Tower) which contain Levels, which contain Tiles or whatever. There's also the player Roster, which contain PCs. There's also a Squad/Party, which also can contain PCs (but smaller). PCs are also in a location, individually in the roster, or as part of a Squad (let's say a Squad can be visiting a location but the PC's "location" variable itself is the home location).

Sooo... thus far, I'm thinking that Entities are just the PCs, and everything else is just data that involves plain Objects? Like, a Location, detailed as it may be, is just an object with member variables in it, as opposed to an Entity with Components that operates in a separate level than PC entities?

OTOH, if the active map in a "quest" has tiles and these have to be drawn on screen, it would make sense that these tiles are also Entities that are looped by the Render System, right? OTOH, Locations are mostly just shown in list format. Then again, so are PCs in certain instances (the roster list, or the Party Screen, and this also could be a separate "system").

Opinions?

EDIT: I'm considering ECSs are maybe overkill for what is a turn based game with a really small amount of "rendered" entities (unless I decide to make it multiplayer somehow :P)
« Last Edit: November 11, 2014, 05:28:02 pm by Sergius »
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6594 on: November 13, 2014, 10:27:23 am »

I'm trying to make a Mario clone on my TI-84 during math and physics.
Problem is, TI lists aren't actually lists, they're arrays.

The enemies here should, obviously, move around, but looping through the entire matrix (I'm using 16x8 matrices as the levels) every "turn" would be far too slow. I thought of using a list (three lists, actually. Ypos, xpos and direction) of creatures instead, but that's obviously hard if I can't just add elements to the list. Any ideas?
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.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6595 on: November 13, 2014, 11:09:56 am »

Problem is, TI lists aren't actually lists, they're arrays.

You're going to have to define lists and arrays. They should be functionally equivalent.
Logged

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6596 on: November 13, 2014, 11:13:35 am »

The enemies here should, obviously, move around, but looping through the entire matrix (I'm using 16x8 matrices as the levels) every "turn" would be far too slow. I thought of using a list (three lists, actually. Ypos, xpos and direction) of creatures instead, but that's obviously hard if I can't just add elements to the list. Any ideas?

Older arcade machines had fixed-length arrays for the game data. They used a "bValid" (or bAlive, or bDead) flag instead of removing things :)
If you have a "spriteid" thing, reserve id 0 for "empty entry".
« Last Edit: November 13, 2014, 11:24:11 am by Thief^ »
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6597 on: November 13, 2014, 11:17:39 am »

The amount of elements in a list can change, the amount of elements in an array cannot.

I thought that that was common terminology, but then again, my programming knowledge is mainly scraped together from many different sources :P

I'm getting worried, I haven't been able to actually find a function to get the length of the array...

Also, to be clear, I'm using only built-in functions and the TI-BASIC interpreter. I can't even do bitwise operations, afaik. Output is done by calling Output(y, x, character). The lists can only contain numbers. I have only 26 number variables and 10 string variables. Functions (of the non-mathemathical kind, anyway) are nonexistent, the closest thing is goto.

So yeah, I don't have sprites. I have three arrays that contain the x position of all monsters, the y position, and their "state" (currently 1 for walking right, 2 for walking left and 0 for dead)
« Last Edit: November 13, 2014, 11:51:16 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.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6598 on: November 13, 2014, 11:30:40 am »

The amount of elements in a list can change, the amount of elements in an array cannot.

I thought that that was common terminology, but then again, my programming knowledge is mainly scraped together from many different sources :P

It's been a while since I worked with a language like that. Sorry, it seems that most of what I learned in intro to CS has now slipped away.
Logged

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6599 on: November 13, 2014, 12:17:41 pm »

I'm getting worried, I haven't been able to actually find a function to get the length of the array...

http://tibasic.wikia.com/wiki/List
http://tibasic.wikia.com/wiki/Dim(
Seems to be Dim()

Looks like you can also alter the length of the array with it
« Last Edit: November 13, 2014, 12:19:23 pm by Thief^ »
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.
Pages: 1 ... 438 439 [440] 441 442 ... 796