• Welcome to The Cave of Dragonflies forums, where the smallest bugs live alongside the strongest dragons.

    Guests are not able to post messages or even read certain areas of the forums. Now, that's boring, don't you think? Registration, on the other hand, is simple, completely free of charge, and does not require you to give out any personal information at all. As soon as you register, you can take part in some of the happy fun things at the forums such as posting messages, voting in polls, sending private messages to people and being told that this is where we drink tea and eat cod.

    Of course I'm not forcing you to do anything if you don't want to, but seriously, what have you got to lose? Five seconds of your life?

Programming Club

Hiikaru

Run.
Pronoun
he
Programming Club
stars-100x100.png




In the interest of more threads to talk in, here's a programming club! I have no idea how many of the people floating around are interested but I know at least a few people are.

Post any questions about programming, resources you found useful, or projects you're working on. Or even just something you're thinking about that's somehow related to programming.

Beginner Resources
Learn Python the Hard Way - Free Python book! Separated into ~50 lessons and oriented toward beginning programmers and especially toward people who are terrified of programming.

Invent With Python - Two free books about making games in Python! One is text games, and one is graphics games. Almost every chapter gives you the full source code for a game and then explains how it works.

Khan Academy Python Videos - Videos on Python by Sal Khan. Each video, he writes a small program and explains it.

#python - IRC channel on Freenode. There are tons of people around willing to help, and they're really friendly to beginners.

Khan Academy JavaScript lessons - JavaScript lessons oriented toward kids (but appropriate for all beginners). You write code in your browser, and you get to make pictures, animations, and games. A voiceover on the lessons will explain the code and talks about things like how functions are just like Pokemon attacks.

Ren'py - A semi-Python thing to write visual novels (it's really basically its own language). It's pretty easy to work with. Appropriate for little kids and up.

Projects
Supybot - A thing to make an IRC bot in Python! You can program them to play games like Apples to Apples or Go Fish, and anyone on IRC can play just by talking to the bot. Windows installation guides here, here, and here. Mac install here. It's also in the Ubuntu repos as supybot (after installing, type supybot-wizard) or you can get it from source.

Project Euler - Math-based programming challenges.

_________________

And if you post about completing some kind of progamming-ish thing, you get a star!
star-yellow-littler.png
 
Last edited:
I've solved ~75 Project Euler problems. The problem I keep having is that I can write a program that I'm 100% certain will get the right answer but it's not very efficient at all.
I can sometimes mess about with some algebra to see if I can work out when it should skip loops etc, but it doesn't make much of a difference. That's the main hurdle I want to get over. I always think something is too easy or way beyond my capability to program, but really I think I'd be much better if I was just better at efficientising the programs I can already write.


A few months ago I wrote a program that displays the Mandelbrot set (here's a picture it made!) and I've made it so you can highlight a certain area and press a button to zoom in, but at the moment it just resets when you zoom in and has to starts its calculations from the start again. And the more you zoom in, the slower it gets. I don't see if there's any way to get around this; seeing as how when you zoom in, the number each pixel represents becomes a longer floating point number and more numbers are added in between the numbers you'd already calculated before you zoomed in. And the longer numbers are the longer the calculations involving them are going to take.
I did once zoom in so far that the screen was just filled with squares of colour because I'd zoomed past the precision of the numbers :P


The library I used for that was pygame, because I'm interested in making simple games eventually, though I'm not sure its particularly useful for displaying mathsy things.
 
I'm beginning to bring my Supybot back from the dead! Hopefully I can actually get him go work this time around. My last attempt, I gave him too many programs and he got really big and slow. :c
 
@Murkrow: That's really impressive! I was under the impression you'd barely programmed at all.

Efficiency is much less important in lots of kinds of programs. Euler problems in particular are often specifically about huge things that would take way too long if you don't do them efficiently.

You know about using the forums on the Project Euler website, right? I haven't done that many problems but I've learned a lot from there.

It takes a long time to learn to write more efficient code so try not to get too discouraged.

Also neat fractal program!

Here are some stars:

murkrow-stars1-small.png


Also what kinds of mathy things for pygame? There's an entire math module in pygame so it seems like it should be okay for displaying some math?

@Qvalador: Huh. How many plugins did you add to him to make him slow? Mine doesn't really go above 30 apparently so I haven't experienced that. For default plugins you could try Anonymous, Math, NickCapture, and Weather. Anonymous lets you go "say hello" or "do a dance" and the bot goes "hello" or "/me a dance" so that's obviously totally useful. NickCapture lets your bot ghost its nickname and renick to it! That's useful if your Internet ever has problems.

But good luck when you set it up again! Here's... a bunny. Because they're lucky.

mohac-bunny-small.png


@thread: I'm not sure what to post about because I have a bunch of random programming-ish things and I haven't really worked on any of them lately. So, here's how my Go Fish game is going:

[12:41] <Hiikaru> ~fish
[12:41] <kittybot> Hiikaru: Thanks for starting the game.
[12:41] <Hiikaru> ~befish
[12:41] <kittybot> Hiikaru: Tried adding you. Did it work?
[12:41] <kittybot> Hiikaru: Hiikaru's hand: ['Nine', 'Eight', 'Queen', 'Ten', 'Three']
[12:41] <Hiikaru2> ~befish
[12:41] <kittybot> Hiikaru2: Tried adding you. Did it work?
[12:41] <kittybot> Hiikaru2: Hiikaru2's hand: ['Queen', 'Two', 'Nine', 'Five', 'Seven']
[12:41] <Hiikaru> ~begin
[12:41] <kittybot> Hiikaru: Okay, the game was locked.
[12:42] <Hiikaru> ~ask Two Hiikaru2
[12:42] <kittybot> Hiikaru: You don't even have that card.
[12:42] <Hiikaru> ~ask Queen Hiikaru2
[12:42] <kittybot> Hiikaru: Hiikaru2 appears to have that card, but you can't take it yet.

It'll have fewer useless commands later, also, obviously it won't actually show your hand to the entire channel. At some point you'll be able to play against AI.
 
... Programming! Uhm.

Okay, I... don't. Each summer I think "I should learn python" and restart Learn Python The Hard Way, and get until about lesson ten until I quit because of lack of use, motivation, etc... and then I forget what I learned, so next summer I start from scratch again. A few people in #tcod might remember that.

Ren'py and the fangames I've played that were made from that (all Dangan Ronpa ones, I think) were really cool and interesting, though! I vaguely want to try that, but without any burning desire for a specific game, and limited artistic ability, that's probably not going to happen anytime soon. Posting in here to add resources, still!
 
... Programming! Uhm.

Okay, I... don't. Each summer I think "I should learn python" and restart Learn Python The Hard Way, and get until about lesson ten until I quit because of lack of use, motivation, etc... and then I forget what I learned, so next summer I start from scratch again. A few people in #tcod might remember that.

Ren'py and the fangames I've played that were made from that (all Dangan Ronpa ones, I think) were really cool and interesting, though! I vaguely want to try that, but without any burning desire for a specific game, and limited artistic ability, that's probably not going to happen anytime soon. Posting in here to add resources, still!

Hi, Mai! Here are some stars for getting so far in Learn Python the Hard Way:

mai-stars1-small.png


Ten lessons is almost 1/5th through the book. If you look at it like that, it's easier to tell that that's actually really good progress.

I think there are two things that make this harder. First is, I think doing something like Python in the summer helps create a feeling like "this is such a huge scary difficult thing that I need to focus on it when I have 100% free time"... but, you no, no pressure or anything... Although that's awesome that you made a plan to do it in summer and then actually went through with it! More than once, it sounds like. Still, why not try Python all year? It could be slow-going if you're busy, but learning slowly is actually good. Rushing through everything with a burning desire to learn how to program your totally epic future game is all well-and-good, but it's practicing over time that really gets things stuck in your head.

Then problem two is feeling like you have to rush through everything with a burning desire to learn how to program your totally epic future game. No, you don't! Why not just draw some random thing and play around with it in Ren'py? It could be fun! Also even just making a tiny game feels pretty cool and you can impress people with it. Like one of my first Flash games was a blue button and when you click on it it makes a sound (and that's it), and my sisters still play it years later. So. But even if you never touch it again, it's still a thing! And practice!

(Also if you ever post about a game where some text happens around bad drawings at least I'll be excited for you, so there's that.)

Anyway thanks for the resource, that looks neat! I'll add it to the list.

_______________________________________________

@thread: And for the sake of sharing progress at things, I wrote a short program in Ren'py.

renpy_test.png


renpy_test2.png

Music plays, and Eevee jumps around on the screen as you click through the dialogue.
 
Hello programmers! Mission Control has a task for you.

I'm working on my bachelor's thesis and it involves a variation on a combinatorial game known as Domineering. Basically: the game is played on a board of squares placed in a grid. Players take turns to cover the squares with dominoes. One player plays dominoes vertically, the other horizontally; and they can't overlap. If a player can't make any more moves, they lose. In the version I am analyzing, there is also an additional rule: at any time, the playing field must be a Young tableau, which means that each row of the playing field must have at least as many squares left as the one above it.

Now, as part of my analysis, I would like to write a program that plays the game, more or less (or at least one that gives me all the information I need for testing, but actually being able to play against the computer would be nice). The idea is to do this by having the program find all possible outcomes of the game, and select an optimal one. Essentially, the program would calculate all the possible moves it can make from a given position, then calculate the player's possible responses to those moves, and so on; this generates a tree, with each node representing a position in the game, and each branch representing a possible move. By drawing the complete tree, the computer can then figure out an optimal path to victory. Obviously this is only feasible for reasonably small instances of the game; otherwise the tree would become too large to handle.

I'll sort it out myself at some point, but in the meantime, if anyone feels like trying their hand at this programming problem, or even just comment on it, I'm sure it could prove useful to me later. I figured it might make for a nice exercise, if nothing else.
 
That's actually another thing about programming that makes me think I'm not particularly good.

I wrote a noughts and crosses game which worked and everything. I drew the grid and you could click where you wanted to put the X or O, and it would tell you if the game is finished.

Then I decided I wanted to make you be able to play against the computer which I thought I could do, since I had played against my friend so much that we'd worked out a strategy do never lose. But I was at a loss as to how to program it. I knew I didn't have to program every single outcome, since I could implement symmetry and not consider any games that wouldn't be reached because the computer would never play moves that could get it there.
But I still couldn't work out how to do it at all, I only managed to make it be able to play one move, either as player 1 or player 2.
 
I made my first program! It's not as much a program as a picture of spaghetti, but hey. It's a big step for me, I've never done this before. Hopefully this is something that works out for me!
 
That's actually another thing about programming that makes me think I'm not particularly good.

I wrote a noughts and crosses game which worked and everything. I drew the grid and you could click where you wanted to put the X or O, and it would tell you if the game is finished.

Then I decided I wanted to make you be able to play against the computer which I thought I could do, since I had played against my friend so much that we'd worked out a strategy do never lose. But I was at a loss as to how to program it. I knew I didn't have to program every single outcome, since I could implement symmetry and not consider any games that wouldn't be reached because the computer would never play moves that could get it there.
But I still couldn't work out how to do it at all, I only managed to make it be able to play one move, either as player 1 or player 2.

If you want assistance on winning moves, this is a list of every possible situation.

...I think making the AI would just take a lot of if/then statements.

Hello programmers! Mission Control has a task for you.

I'm working on my bachelor's thesis and it involves a variation on a combinatorial game known as Domineering. Basically: the game is played on a board of squares placed in a grid. Players take turns to cover the squares with dominoes. One player plays dominoes vertically, the other horizontally; and they can't overlap. If a player can't make any more moves, they lose. In the version I am analyzing, there is also an additional rule: at any time, the playing field must be a Young tableau, which means that each row of the playing field must have at least as many squares left as the one above it.

Now, as part of my analysis, I would like to write a program that plays the game, more or less (or at least one that gives me all the information I need for testing, but actually being able to play against the computer would be nice). The idea is to do this by having the program find all possible outcomes of the game, and select an optimal one. Essentially, the program would calculate all the possible moves it can make from a given position, then calculate the player's possible responses to those moves, and so on; this generates a tree, with each node representing a position in the game, and each branch representing a possible move. By drawing the complete tree, the computer can then figure out an optimal path to victory. Obviously this is only feasible for reasonably small instances of the game; otherwise the tree would become too large to handle.

I'll sort it out myself at some point, but in the meantime, if anyone feels like trying their hand at this programming problem, or even just comment on it, I'm sure it could prove useful to me later. I figured it might make for a nice exercise, if nothing else.

If I have time, I might try this in C++. It sounds interesting.
 
Hiikaru helped me make a fortune-telling plugin for my Supybot! It works pretty much seamlessly, it's pretty cool.
 
I don't program often because as I said before I rarely had any ideas. It makes me sad.

Anyway yesterday I decided I'd try programming 2048, and I managed it!
My version is probably badly done and it isn't as polished (the squares don't animate or anything)


Now I'm out of ideas again :(
I tried writing a class that's essentially a maths function but refers to its derivative as well. It's almost working but in trying to make one for cos, I can't work out how to say its derivative is -sin without creating a completely separate instance of this function class that is essentially the negative of sin. I don't want to do that because I already have sin.
Although while writing this out I just realised I might be able to use the code I wrote that generates a new function f(g(x)) given f and g, by setting g to be sin and f to be the polynomial -x.


Also a quick question, if I wanted to write a program that draws a graph, what would be the best way to draw the line? I did one a few years ago with the naïve approach of going through every x value, getting its y value and putting a dot on the screen. It's fast but doesn't work with implicit functions and if it grows quickly it's a bunch of dots rather than lines.
Would a good method be to go through every pixel on the screen and determining whether its (x, y) value lies within a certain radius of an actual solution? It would probably make a nice line if the given function was nice but I'm a bit worried that going through every pixel on the screen individually might not be very efficient. (the mandelbrot thing I posted earlier did this and it took ages)
 
I made my own Twitch Plays x program! I even figured out how to stream to Twitch from Linux, whee. On Python on Linux you use xdotool like this:

Code:
mport subprocess
import random
import time

window_id = subprocess.check_output(["xdotool", "search", "--name", "ZSNES"])

subprocess.call(["xdotool", "windowfocus", window_id])

while True:
    button = random.choice(["Up", "Down", "Left", "Right"])
    print button

    for i in range(0, 1):
        subprocess.call(["xdotool", "keydown", "%s" %button])
        time.sleep(0.5)
        subprocess.call(["xdotool", "keyup", "%s" %button])

This is the version that just presses random directions. My little sister really likes to play by fighting it with the keyboard. We mostly did Bomberman Tournament and the RNG continually puts down bombs and then runs into a corner next to the bomb so that it can't get away in time.

There's some other way to do this where you write code specifically for the emulator, but I don't know how to do that and this way works fine.

@Music Dragon That's a really interesting programming idea! I read about it and played the Kongregate version to try and get the hang of how the game works. I think I'll try programming it eventually. I'm really interested in programming AI in general so it might be good practice.

@Majora hooray! Spaghetti star, Fortune-telling plugin star:
mohac-star1-small.png
mohac-star2-small.png


@Murkrow
murkrow-star1-small.png
murkrow-star2-small.png
murkrow-star3-small.png


That's actually another thing about programming that makes me think I'm not particularly good. [...] Then I decided I wanted to make you be able to play against the computer [...]

That doesn't mean you're not good! That just means sometimes programming is hard. Getting the computer to play one move is still a start! Like Superbird said, you can do it a really messy way with tons of if/then statements, so it might work to start there and then see if you start thinking of any ways to simplify the code. Or, you could start out with having the computer play totally random moves?

It'd probably also be easier if you started out by programming it intending to write AI. I don't know how your program works, but it's usually a lot harder to add unexpected things. So you could try starting from scratch!

I don't program often because as I said before I rarely had any ideas. It makes me sad. [...] Now I'm out of ideas again :(
[...]

Do you run out of any ideas, or just out of ideas that you feel like you could feasibly program? Also, if you like Project Euler, maybe you could find a similar list of things to do? I don't know any really good ones (though you could browse Invent with Python), but you could ask around on the #python IRC channel on Freenode.

If it's that you don't know how to do your ideas, you could break them into little pieces! Like if you don't know how to make... an entire platformer, you could start by making a game where you walk around a blank screen with the arrow keys.

Otherwise, I make a lot of programs for friends or whoever. Like sometimes I learn how to program something so I can help someone else do it (I spent a lot of time on Ren'Py to teach my little sister how to use it), or someone mentions some task that could be automated (renaming tons of files, going through the hotspot thing on hotel Internet, downloading a list of things), or someone asks me to do something, or mentions something they'd do if they could program and/or cared enough to program it.

Also I have lots of ideas from playing video games or not playing them because I can't find one that's like what I want. Programming entire games is hard but sometimes I do small tests for game ideas.

Although while writing this out I just realised I might be able to use the code I wrote that generates a new function f(g(x)) given f and g, by setting g to be sin and f to be the polynomial -x.

Writing about programming problems (or really any problems, but this is a programming thread) often helps! Also you could get help from #python! Or at least prepare to get help from #python, because thinking of how to describe the problem to strangers and cut down the code to show off the problem better really helps.

Also a quick question, if I wanted to write a program that draws a graph, what would be the best way to draw the line? I did one a few years ago with the naïve approach of going through every x value, getting its y value and putting a dot on the screen. It's fast but doesn't work with implicit functions and if it grows quickly it's a bunch of dots rather than lines.
Would a good method be to go through every pixel on the screen and determining whether its (x, y) value lies within a certain radius of an actual solution? It would probably make a nice line if the given function was nice but I'm a bit worried that going through every pixel on the screen individually might not be very efficient. (the mandelbrot thing I posted earlier did this and it took ages)

Does it need to be in pygame (if you're still using that) or something, or can it be anything? I don't know much about graphing but you could try matplotlib or graph-tool. Even just trying them out might give you some ideas for what you want to be doing.

(or ask #python!)
 
That doesn't mean you're not good! That just means sometimes programming is hard. Getting the computer to play one move is still a start! Like Superbird said, you can do it a really messy way with tons of if/then statements, so it might work to start there and then see if you start thinking of any ways to simplify the code. Or, you could start out with having the computer play totally random moves?

It'd probably also be easier if you started out by programming it intending to write AI. I don't know how your program works, but it's usually a lot harder to add unexpected things. So you could try starting from scratch!

I would try to write a bunch of if statements and shorten it but the sheer amount of possible moves put me off doing that. I guess I should try redoing some of it though, to make it easier to work with the symmetries. Other than that I'm not sure how to redo it to make it easier for an AI. All it really needs is to able to see what's currently in the grid and be able to call the "make a move" function. I can't think of anything else it could need.

Do you run out of any ideas, or just out of ideas that you feel like you could feasibly program?
If it's that you don't know how to do your ideas, you could break them into little pieces! Like if you don't know how to make... an entire platformer, you could start by making a game where you walk around a blank screen with the arrow keys.
I run out of any ideas. I do have ideas that aren't feasible and they're so unfeasible they're not even worth mentioning.

I do do that sometimes. I did make a program where a thing walks around a blank screen. I didn't do anything beyond that because I couldn't think of an actual game to grow out of it, and also my incredibly short attention span :c

Otherwise, I make a lot of programs for friends or whoever. Like sometimes I learn how to program something so I can help someone else do it (I spent a lot of time on Ren'Py to teach my little sister how to use it), or someone mentions some task that could be automated (renaming tons of files, going through the hotspot thing on hotel Internet, downloading a list of things), or someone asks me to do something, or mentions something they'd do if they could program and/or cared enough to program it.

That's really admirable. I'm far too un-selfless (selfish isn't the right word I'm looking for here) to learn something just for the sake of helping someone else learn it. I do tend to work better when someone else is relying on me but that's usually when they specifically ask me to do the thing.


Writing about programming problems (or really any problems, but this is a programming thread) often helps! Also you could get help from #python! Or at least prepare to get help from #python, because thinking of how to describe the problem to strangers and cut down the code to show off the problem better really helps)
Writing about them definitely helps. There's something about explaining the problem to other people that sometimes makes you think of the answer as you're trying to put it into words. I think there's even a wiki article on that phenomenon. "rubber duck programming" or something like that.

I don't particularly want to go to #python though. Strangers. Too shy. :(

Does it need to be in pygame (if you're still using that) or something, or can it be anything? I don't know much about graphing but you could try matplotlib or graph-tool. Even just trying them out might give you some ideas for what you want to be doing.

Well I wasn't looking to do actual graphing work. If I were doing something completely different that happened to need graphs I'd look for a library to use but what I'm doing is just seeing if I can write something that draws graphs. Nothing too fancy. I figured trying to find a way to draw them that's both efficient and looks good would give some good experience.

That second link isn't the right kind of graphs :P
Though coincidentally I was also working on a program that draws that kind of graph, too. I got so far as to have the graphs represented in the computer but I hadn't made it draw them yet, since I had no idea how to make economical use of the space on the screen. (i.e. try to draw the graph in such a way that there are as few edge-crossings as possible, etc)
 
Back
Top Bottom