Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3

Author Topic: DF in python?  (Read 9900 times)

Froggie

  • Bay Watcher
    • View Profile
DF in python?
« on: September 30, 2012, 02:13:43 pm »

I have just got interested in coding and after a few google searches i have deduced that the easiest language to start with would be python and my ability in said language is wanting to say the least, when my ability improves im hoping to be able to make at least simple rogue-likes and similar projects. but i understand toady uses C++ and was wondering would python be able to create something at all like DF?
Logged

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: DF in python?
« Reply #1 on: September 30, 2012, 03:58:08 pm »

You might want to move this to the General Discussion/Creative Projects/Whatever is more appropriate than here board.

Nonetheless, it would be doable, but at the end of the day, but it will be slower, partially due to the interpretedness (this is now a word) of Python.
Logged

GreatWyrmGold

  • Bay Watcher
  • Sane, by the local standards.
    • View Profile
Re: DF in python?
« Reply #2 on: September 30, 2012, 05:11:13 pm »

You can mod DF with Notepad. Why would you need Python?
Logged
Sig
Are you a GM with players who haven't posted? TheDelinquent Players Help will have Bay12 give you an action!
[GreatWyrmGold] gets a little crown. May it forever be his mark of Cain; let no one argue pointless subjects with him lest they receive the same.

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: DF in python?
« Reply #3 on: September 30, 2012, 08:16:33 pm »

You can mod DF with Notepad. Why would you need Python?

To write a spinoff.

Froggie

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #4 on: October 01, 2012, 09:52:09 am »

@Pufferfish
not exactly a spinoff, i just wanted to now if games could be created in python and as i wouldnt really make anything more advanced(or anywhere near as good) as DF.

@MadocComadrin
aah... i didnt really know where a question about coding would go. How would i go about moving this?
Logged

Starver

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #5 on: October 01, 2012, 10:10:52 am »

There are very few programming(/scripting) languages where you can't create a game, and I'm fairly sure Python can do the necessary calculations (albeit with the FPS will be a lot worse, for a given amount of background complexity, compared to DF's C++ construction), because I've seen (very) approximate Python things.

Python is indeed supposed to be a very good language to learn with.  As to whether it's necessarily the best one (even excluding specialist "game constructor" environments, that have a capability to run a rogue-like ethos[1]) to bash up even a simple DF-clone is another matter.

But trying will be probably be fun, and should be informative regardless (a kind of meta-"Losing is Fun"!).  I say give it a go, if you're already so inclined!

[1] I don't include "Click'N'Play"-type things in this, unless they've updated that platform significantly.  Too much bling, for my liking, last time I saw it.
Logged

Froggie

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #6 on: October 01, 2012, 10:18:10 am »

Thanks for the great answer but since other languages such as C++ are better for games ,i would like to learn them at some point in my life ,albeit after ive learned python. What i was wondering is : would learnig python make learning other languages after that easier? because the syntax would be different but i guess you would kind of already get how it works. thanks again for the help, learning to program has long been a goal of mine. :)
Logged

Starver

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #7 on: October 01, 2012, 10:55:50 am »

I'm no expert in Python, itself (keep meaning to get into it), but I believe that it shares a lot with most of the other 'modern' languages.  I'd say there'd be some syntactical differences (semi-colons as command terminators or not?), maybe what certain test operators are (!= or <>, for example), how tightly/loosely typed data is, how you ensure libraries are requested, etc.

But generally a procedure/function-call is a procedure or function call, once you get down to it, beyond some (ultimately) trivial things such as whether it's call-by-reference or call-by-value, as long as you understand the differences between your 'starting' language.  Object handling in more OO programming seems to be gravitating to similar syntax and purposes (give or take extensions and limitations, again which you can pick up).  You're learning concepts that are portable, and while Python->LISP might be a bit of a jump, going from Python to an actual main member of the C-family languages (save for K&R C, reverying back to pre-OO methodologies, perhaps) shouldn't be a great leap.

Certainly reading such a new language (in my experience) will just be a bit like a heavily-accented/dialected version of what you already know, with perhaps a few misunderstandings[1] that you eventually work around.  Translating to that language could of course be harder, because you (if you're lucky) get given errors about where you've used a wrong syntactic format or a non-existent function, although perhaps (if you're unlucky) you find somewhere where it becomes a valid-but-different mistranslation that doesn't bring up an immediate error.


But it's probably different for everyone.  I've no idea if you're completely new to programming or are just transitioning from something else that's dissimilar.


[1] There's a tale from some war or other (Korean?) where a British commander was asked by a US general how he was doing with his part of the front-line.  "It's a bit sticky here", or similar, was the reply, which was taken as "Not bad, could be better", but was actually supposed to indicate that things weren't going well at all.  Anyway, maybe a bad example, but just came to mind.
Logged

somebears

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #8 on: October 01, 2012, 11:05:31 am »

I'd say this depends on your way of learning.

If you start with python its like DF when all labors are automagically assigned, rooms automatically assigned and the furniture put in place. It is much like the manager:say what you want and you get it (usually)

c++ (for example) Is the way DF is right now. You need to care about every little thing. No manager.

So if you like a big challenge first and an easier life afterwards you should start with c++ (or sth like it)

If you are good in adapting then python is the better choice...

Python also wins if you don't plan to learn c++.


so:
Python:
+ easy
+ fast (to code)
+ flexible
+ you can replace bottleneck code parts with c++ (or sth else)
+ script language
- slower to execute (NOT slow)
- you often need an interface to interact with some hardware

C++
+ insanely fast to execute
+ good interaction with hardware
- programming can be a pain in the arse
- harder to learn
- platform-dependent
- need to compile/link
 

I add stuff if I manage to find some more



PS: To stay whith the language thing I'd say python is a language where the grammar is done for you
Logged

Askot Bokbondeler

  • Bay Watcher
  • please line up orderly
    • View Profile
Re: DF in python?
« Reply #9 on: October 01, 2012, 01:34:37 pm »

ptw

zombie urist

  • Bay Watcher
  • [NOT_LIVING]
    • View Profile
Re: DF in python?
« Reply #10 on: October 01, 2012, 02:09:29 pm »

My only advice is to don't expect your first project to be DF.  ;)
Logged
The worst part of all of this is that Shakerag won.

Froggie

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #11 on: October 02, 2012, 09:50:31 am »

haha, ill try not to. The extent of my skill is making the computer have a clunky, badly coded conversation with you.  8)
Logged

Akjosch

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #12 on: October 02, 2012, 10:38:59 am »

(...)  beyond some (ultimately) trivial things such as whether it's call-by-reference or call-by-value, (...)

Funny you should mention it, because Python does neither while passing arguments. It does call-by-sharing instead. :)

Logged

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: DF in python?
« Reply #13 on: October 02, 2012, 11:45:10 am »

You say call-by-sharing, I say non-visible pass-by-reference. :P (or reference-passed-by-value).

the grammar is done for you
The grammar has to be done before the parser is even made. :/
Logged

Starver

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #14 on: October 02, 2012, 11:55:16 am »

Strange.  I'd consider that as call-by-reference, but I'm probably wrong.  But (as far as I can see) it doesn't have all the messy syntax you'd normally use when forcing call-by-reference in a call-by-value default (by passing, as the value, the value of the reference to the original value, IYSWIM).  And, in my mind, that means that it's a call-by-reference.  I still have to get my mind around what that Wiki text says.

[Ah, ninjaed by MadocComadrin, while messing about with the following...  Those are better descriptions.]

Here, want some Perl?  I like Perl.  It's my favourite 'hack something up' language.  Probably why I've not tried to get into Python, too much, yet.  It's probably ugly and hard to read, but I've put some comments (anything after "#" on a line, or lines starting with "#").

Code: (Perl example) [Select]
#!/bin/perl
use strict;
use warnings;

# Procedures we'll use
sub Swap1 { # A call-by-reference example (using explicit references)
  my ($ref1,$ref2) = @_; # Assign the first two parameters to $ref1 and $ref2, if any.  No error-checking being done.
  my $temp  = $$ref1; # Variable $temp contains whatever '$' value that $ref1 may reference
     $$ref1 = $$ref2; # The '$' value that $ref1 references is set to whatever the '$' value is that $ref2 references
     $$ref2 = $temp;  # The '$' value that $ref2 references is set to whatever value $temp /actually is/.
  return 0; # (Unnecessary, but a placeholder for success...
            #  We could have tested whether we have two arguments at the start,
            #  and that both are actually references, and on failure return something else...)
} # end of sub Swap1

sub Swap2 { # A call-by-value example (takes values and returns values)
  my ($val1,$val2) = @_; # Just take whatever values we want (values, references, doesn't care);
  my $temp = $val1; # Copy the $val1 value into $temp;
     $val1 = $val2; # Copy the $val2 value into $val1;
     $val2 = $temp; # Copy the $temp value in $val2;
  return ($val1,$val2); # return the two values back to the caller
} # end of sub Swap2

sub Swap2b { # Another
  my ($val1,$val2) = @_; # Get the idea?
  return ($val2,$val1);  # Even easier.
} # end of sub Swap2b

sub Swap2c {
  return reverse @_; # Functionally the same as Swap2 and Swap2b, if /exactly/ two parameters passed
} # end of sub Swap2c

sub DontSwap { return @_; } # end of DontSwap.  Silly thing to do, but...

sub Swap3 {
  # This time, let's just operate /directly/ on the "@_" import-variable...
  my $temp = $_[0]; # The zero-indexed (first item) is copied to $temp
     $_[0] = $_[1]; # the one-indexed (second item) is copied onto the zero-indexed one
     $_[1] = $temp; # Guess...
  return 0; # Yeah, we should have tested to make sure the above doesn't error,
            # so we might as well not have bothered returning anything /either/
} # end of sub Swap3


# And now, in use...
my ($first,$second) = ("Item A", "Item B"); # Assigns "Item A" to the variable $first, and "Item B to the variable $second
print "First is '$first' and second is '$second' (Initially!)\n";
#???? "First is 'Item A' and second is 'Item B'"

Swap1(\$first,\$second); # The *reference* to $first and the *reference* to $second are passed
print "First is '$first' and second is '$second' (After Swap1!)\n";
#???? "First is 'Item B' and second is 'Item A'"   (They swapped!)

Swap2($first,$second); # The value of $first and the value to $second are passed
print "First is '$first' and second is '$second' (After Swap2 -wrongly!)\n";
#???? "First is 'Item B' and second is 'Item A'"   (They /stayed/ swapped, they changed internally only)

($first,$second) = Swap2($first,$second); # The value of $first and the value to $second are passed,
                                          #  and the resulting array from "Swap2" is applied back to $first and $second
print "First is '$first' and second is '$second' (After Swap2 - correctly!)\n";
#???? "First is 'Item A' and second is 'Item B'"   (This resulted in being back-swapped)

($first,$second) = Swap2b($first,$second); # The value of $first and the value to $second are passed,
                                           #  and the resulting array from "Swap2b" is applied back to $first and $second
print "First is '$first' and second is '$second' (After Swap2b!)\n";
#???? "First is 'Item B' and second is 'Item A'"   (This resulted in being re-swapped)

($first,$second) = Swap2c($first,$second); # The value of $first and the value to $second are passed,
                                           #  and the resulting array from "Swap2c" is applied back to $first and $second
print "First is '$first' and second is '$second' (After Swap2c!)\n";
#???? "First is 'Item A' and second is 'Item B'"   (This resulted in being back-swapped, again!)

($second,$first) = DontSwap($first,$second); # The value of $first and the value to $second are passed,
                                              #  and the resulting array from "DontSwap" is applied back to $second (first)
                                              #  and /then/ $first (second)...
print "First is '$first' and second is '$second' (After DontSwap!)\n";
#???? "First is 'Item B' and second is 'Item A'"   (This resulted in being re-re-swapped!)

Swap3($first,$second); # This version does a tricky call-by-reference sort of thing, without needing "\$references" defining!
print "First is '$first' and second is '$second' (After Swap3!)\n";
#???? "First is 'Item A' and second is 'Item B'"   (Ooh look, back to normal)

Code: (The actual output) [Select]
First is 'Item A' and second is 'Item B' (Initially!)
First is 'Item B' and second is 'Item A' (After Swap1!)
First is 'Item B' and second is 'Item A' (After Swap2 -wrongly!)
First is 'Item A' and second is 'Item B' (After Swap2 - correctly!)
First is 'Item B' and second is 'Item A' (After Swap2b!)
First is 'Item A' and second is 'Item B' (After Swap2c!)
First is 'Item B' and second is 'Item A' (After DontSwap!)
First is 'Item A' and second is 'Item B' (After Swap3!)

Whoops, nearly forgot...  Consider the following as well...
Code: (More Perl (appended to above)) [Select]
my ($third,$fourth) = ("Item C", "Item D"); # yadayadayada
my $thirdRef=\$third; my $fourthRef=\$fourth;

Swap2($thirdRef,$fourthRef); # This won't do anything interesting
print "Third is $third, Fourth is $fourth\n";
# Expect Third as Item C, Fourth as Item D, still

($thirdRef,$fourthRef)=Swap2($thirdRef,$fourthRef); # We're sending and swapping the /references/!!!
print "Third is $third, Fourth is $fourth\n";
# Expect Third as Item C, Fourth as Item D, still, because $third and $fourth weren't changed, but...

print "Third's apparent Reference is pointing at $$thirdRef, and Fourth's is pointing at $$fourthRef\n";
# Expect Third's Referenced thing as Item D, Fourth's as Item C... swapped!

Swap3($thirdRef,$fourthRef);
print "Third's apparent Reference is pointing at $$thirdRef, and Fourth's is pointing at $$fourthRef\n";
# Expect Third's Referenced thing as Item C, Fourth's as Item D... swapped back!

Code: (Resulting in) [Select]
Third is Item C, Fourth is Item D
Third is Item C, Fourth is Item D
Third's apparent Reference is pointing at Item D, and Fourth's is pointing at Item C
Third's apparent Reference is pointing at Item C, and Fourth's is pointing at Item D

Yes, it's messy, and I stuck purely to Function Orientated code...  Anyway, don't mind me.


Logged
Pages: [1] 2 3