Bay 12 Games Forum

Please login or register.

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

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

Shadowlord

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9600 on: May 24, 2016, 05:37:44 pm »

What kind of project is it?
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

GameBoyBlue

  • Bay Watcher
  • Turn to face the strange
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9601 on: May 25, 2016, 08:00:40 am »

What kind of project is it?

Atari Style game bonus points if it actually would run on some kind of Atari simulator but that's not necessary. Need someone able do program simulations. I'd handle the art of the project.
Logged

breadman

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9602 on: May 25, 2016, 01:23:28 pm »

Imagine you have two targets, one that is close according to the heuristic but actually blocked off by a complicated maze (target A), and one that is far away but unobstructed and thus quicker to reach (target B).  The algorithm will start moving towards A until it hits the maze.  At which point it might randomly hit a tile where the heuristic says B is closer and "lock on" to B.  Alternatively it won't and it will eventually find its way through the maze to A.  In both cases it will produce an inefficient path.  If it gets through the maze then it will be taking a longer than necessary path to reach a target (since it should have gone to B).  However if it hits B things will be even worse as it will make a path that starts going towards A and then "changes its mind" and goes towards B.
I doubt that this will happen.  The algorithm takes the cost of the current path into account, so before it hits that magic tile where B is closer, it decides that the heuristic for the tile one step towards B is lower than the current cost+heuristic for the A path.  At that point, it abandons the A path entirely, because cost+heuristic for an unobstructed B path never* increases.

* Ideally, anyway.  DF's default path weight is twice as large as its heuristic value, which also causes slowdown.

Granted, either scenario is better than DF's current habit of locking on to A before pathfinding, even if the path to A takes it right next to B.
Logged
Quote from: Kevin Wayne, in r.g.r.n
Is a "diety" the being pictured by one of those extremely skinny aboriginal statues?

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9603 on: May 25, 2016, 04:30:05 pm »

You're right, I didn't think of that.
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

Bumber

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

Could it be that you're not following the proper calling convention that printf uses?
And what would that be?
I'm pretty sure parameters go into registers before they go on the stack. I have no idea which assembly language you're using, but here's how I'd do it:
Code: (Intel x86-64 Assembly) [Select]
;==========================================================================================================================================================================
;The parameter order for integers is: RDI, RSI, RDX, RCX, r8, r9, stack
;The parameter order for floats is: xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, stack
;RAX should be set to number of xmm registers used, up to 8.
;Once int and float are both using stack, they are read as needed in parameter order.
;==========================================================================================================================================================================
extern printf                                               ;C library function for common output. 1st parameter is pointer to a c_string, followed by format parameters
;Typically, you'd have RDI point to a format string like "%s %ld %lf", then RSI = address of another string, RDX = 64-bit int, xmm0 = 64-bit float, RAX = 1

global test_main                                            ;Make this program callable by other programs
;==========================================================================================================================================================================
segment .data                                               ;Initialized data are placed in this segment

align 16                                                    ;Start the data on a 16-byte boundary
message db "This is text", 10, 0                            ;"This is text\n"
message2 db "It is linked with the C library", 10, 0        ;"It is linked with the C library\n"
message3 db "As you can see, I call printf to print out these messages", 10, 0
;"As you can see, I call printf to print out these messages\n"

;==========================================================================================================================================================================
segment .bss                                                ;Uninitialized data are declared in this segment. It is good practice to always write all three segments
;==========================================================================================================================================================================
segment .text                                               ;Instructions are placed in this segment

test_main:                                                  ;The start of the function's execution
push rbp                                                    ;This marks the start of a new stack frame belonging to this execution of this function
mov  rbp, rsp                                               ;rbp holds the address of the start of this new stack frame, makes program compatible with C language

;The program can crash if the stack isn't aligned to a 16-byte boundary before the function call,
;in which case you should "push qword 0". I've only had this issue with scanf, not printf
mov       rdi, message                                      ;rdi is the first parameter, a pointer to the string
mov qword rax, 0                                            ;Zero in rax indicates printf receives no data (floating point) from vector registers
call      printf                                            ;An external function handles output

mov       rdi, message2                                     ;rdi is the first parameter, a pointer to the string
mov qword rax, 0                                            ;Zero in rax indicates printf receives no data (floating point) from vector registers
call      printf                                            ;An external function handles output

mov       rdi, message3                                     ;rdi is the first parameter, a pointer to the string
mov qword rax, 0                                            ;Zero in rax indicates printf receives no data (floating point) from vector registers
call      printf                                            ;An external function handles output
;==========================================================================================================================================================================
mov qword rax, 0                                            ;Set return value to 0 just to be safe, even though this function is void
pop rbp                                                     ;Restore the value rbp held when this function began execution

ret                                                         ;Pop an 8-byte integer from the system stack, place a copy in rip, resume execution at the address in rip.
Code: (C) [Select]
#include <stdio.h>

extern void test_main(); //The assembly sub-program. Prints 3 messages then returns

int main()
{
printf("This is the driver program. Now calling assembly function:\n\n");
test_main(); //Call the main assembly program
printf("\nFunction returned. The driver will now return 0 to the operating system.\n");
return 0;
}
Code: (Compile and execute on Linux) [Select]
nasm -f elf64 -l test_main.lis -o test_main.o test_main.asm
gcc -c -m64 -Wall -std=c99 -l testdriver.lis -o testdriver.o testdriver.c
gcc -m64 -o test.out testdriver.o test_main.o
./test.out
« Last Edit: May 26, 2016, 01:36:37 am by Bumber »
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)?

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9605 on: May 25, 2016, 07:17:49 pm »

What kind of project is it?

Atari Style game bonus points if it actually would run on some kind of Atari simulator but that's not necessary. Need someone able do program simulations. I'd handle the art of the project.
Consider doing a mockup in either Unity or Gamemaker. Unity is a more valuable skill, but is more involved. You can port it to an emulator or similar later on.

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9606 on: May 26, 2016, 01:25:37 am »

Python problem. Suppose I have a dictionary defined as such:
Code: (Python) [Select]
table = {}
table["Key"] = ("String",[(True,"Alice"),(False,"Charlie"),(True,"Bob")])
What's the best or most efficient way to check if a given name exists or not in a tuple of the list table["Key"][1], then remove the tuple that contains it?
« Last Edit: May 26, 2016, 01:38:56 am by Bumber »
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)?

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #9607 on: May 26, 2016, 04:17:47 am »

You can call table.keys() which returns a list of all keys in the dictionary, then check if it's in there.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Avis-Mergulus

  • Bay Watcher
  • This adorable animal can't work.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9608 on: May 26, 2016, 05:59:50 am »

Python problem. Suppose I have a dictionary defined as such:
Code: (Python) [Select]
table = {}
table["Key"] = ("String",[(True,"Alice"),(False,"Charlie"),(True,"Bob")])
What's the best or most efficient way to check if a given name exists or not in a tuple of the list table["Key"][1], then remove the tuple that contains it?
I would do this:
Code: [Select]
table['Key'][1] = [tuple for tuple in table['Key'][1] if name not in tuple]

You can call table.keys() which returns a list of all keys in the dictionary, then check if it's in there.
We're looking in the values, though.
Logged
“See this Payam!” cried the gods, “He deceives us! He cruelly abuses our lustful hearts!”

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #9609 on: May 26, 2016, 06:18:16 am »

Reading comprehension is what now
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9610 on: May 26, 2016, 01:45:28 pm »

Worked out why my program I posted about earlier crashes. It crashes at the point where it tries to read from a file containing binary data of a class instance into an empty class instance. The class has private members so I think that that is what's breaking it.

Spoiler (click to show/hide)

Tried writing a class method that would use the this pointer to specify fstream's read function to load the class data to the instance that calls the method. Also crashes the program.

Spoiler (click to show/hide)

I haven't tried input/output of class objects to files. I thought it'd work like with structs, just calling fstream's read and write methods and letting them do whatever it is they do.

Tips? Help? Not really sure what to do from here. Considering just changing the class to a struct. But I'd like to know how to use file i/o with classes for future applications.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

DrunkGamer

  • Bay Watcher
  • Beer loving Gentledwarf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9611 on: May 26, 2016, 01:46:29 pm »

I had a rather long time of not touching a computer outside of work, but finaly I'm capable of practicing coding

And oh god am I crap on it. Doing a project with Python, and so far so good. A generator, like one of the first projects I did, to warm myself up and try to expand it further.

My code is absolutely horrifying, though. 96 Lines of code (That without counting the 30 lines of lists on another .py document I use as a database in an attempt to make it less confusing to navigate the "main" code) to generate this text

Code: [Select]
Malpe, The Great Spirit of Destruction
Culture: Native American

Malpe is a Great Spirit originating from Native American cultures. It is seen as the Great Spirit of Destruction. It is generally depicted as a Non-Corporeal Being.

Description:
Malpe is a Non-Corporeal Being, and as such, has no common physical form. But it is known to manifest as a Plover

Code: [Select]
Tarron, The God of Philosopy
Culture: Western

Tarron is a God originating from Western cultures. He is seen as the God of Philosopy. He is generally depicted as a Male.

Description:
Tarron is generally depicted as a Human with [HERE GOES EXTENSIVE DESCRIPTION OF HIS/HER LOOKS].

Well, at least the names are truly randombly generated out of real God names mashed together instead of just picked from a list
Logged

Shadowlord

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9612 on: May 26, 2016, 01:48:16 pm »

Wondering why code blocks inside spoilers are so unreadably small, but code blocks outside spoilers are not...
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

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9613 on: May 26, 2016, 01:49:15 pm »

But, they aren't?
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.

Shadowlord

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9614 on: May 26, 2016, 01:53:00 pm »

Spoiler (click to show/hide)
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
Pages: 1 ... 639 640 [641] 642 643 ... 796