Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Poll

What programming topic would you want the next challenge to be about?  (It might be a good opportunity to focus on a subject you're not familiar with or to reinforce knowledge on one that you already know)

Control Flow
- 2 (2.2%)
Arrays, Strings, Pointers, and References
- 8 (9%)
Functions
- 4 (4.5%)
Basic object-oriented programming
- 30 (33.7%)
A bit more advanced OOP (Composition, Operator overloading, Inheritance, Virtual Functions)
- 18 (20.2%)
Templates
- 8 (9%)
Other (Explain)
- 4 (4.5%)
Working with files?  (Streams)
- 15 (16.9%)

Total Members Voted: 89


Pages: 1 ... 30 31 [32] 33 34 ... 78

Author Topic: Programming Challenges & Resources (#bay12prog) Initiative  (Read 95991 times)

stummel

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #465 on: November 27, 2010, 05:47:33 pm »

Oh, and any idea how to make a text parser for games a la Zork?

You should read && learn about formal languages. But as a start to understand and to work with, this should be fine:

http://en.wikipedia.org/wiki/Recursive_descent_parser#Example_parser

I've never written a real parser on my own, only do know some theoretical stuff. So there should be better advisors round here =)

edit²:

http://rosettacode.org/wiki/Arithmetic_Evaluator/C

You might give this a try. If you understand this, then there shouldn't be any magic about basic parsing for you.

edit³:
 
Or this one. Source from a professor of mine. So comments and output in German. But it's pretty clear what he wants to do (despite those ugly variable names).

Code: [Select]
//************************************************************************
// Simulation eines TASCHENRECHNERS
// Zunächst wird die Syntax arithmetischer Ausdrücke geprüft, sodann
// werden diese in UPN umgewandelt und schließlich mit Hilfe eines
// Stacks ausgewertet.
//************************************************************************
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
//-----------------------------------------------------------------------
// Funktion calc mit Scanner, Parser und Berechnungs-Modul
// x: Zeiger auf das Ergebnis
// str[]: Eingabe-String
// Rückgabewert: -1 wenn ein Fehler aufgetreten ist, sonst 0
//-----------------------------------------------------------------------
int calc(double *x, char str[])
{

int iop_rank[5]={1,1,2,2,3};                           // Operator-Ränge
char c,c0,text[80];
int icode[80],ipol[40],itmp[40],iranks[40];
int i,j,k,len,ii,ix,iq,ir,ip,it,is,pflg,eflg;
double fcode[40],stack[40];
c0=0;          //**** SCANNER: Erzeugung des numerischen Zwischen-Codes
i=eflg=pflg=0;                                      // Flags vorbesetzen
ii=ix=it=-1;
len=strlen(str);
while(i<len) {                             // Eingabe-String durchlaufen
  c=str[i++];
  switch(c) {                                      // Operator bestimmen
    case '-': if(c0=='E' || c0=='e') k=0; else k=100; break;
    case '+': k=101; break;
    case '*': k=102; break;
    case '/': k=103; break;
    case '(': k=105; break;
    case ')': k=106; break;
    default: k=0;
  }
  if(k>=100) {                                      // Operator gefunden
    if(it>=0) {
      text[++it]=0;
      it=-1;
      eflg=pflg=0;
      icode[++ii]=++ix;
      fcode[ix]=atof(text);
    }
    icode[++ii]=k;
  }
  else {                                 // Operand (Real-Zahl) gefunden
    if(c=='.' || c=='-' || c=='E' || c=='e' || (c>47 && c<58))
    text[++it]=c;
    else return(-1);
    if(c=='.')    { if(eflg || pflg) return(-1); pflg=1; }
    if(c=='E' || c=='e') { if(eflg) return(-1); eflg=1; }
  }
  c0=c;
}
if(it>=0) {                           // Letztes Zeichen war ein Operand
  text[++it]=0;
  icode[++ii]=++ix;
  fcode[ix]=atof(text);
}
j=k=icode[0];           //**** PARSER: Syntax des ersten Zeichens prüfen
if(k!=105 && k!=100 && k>=100) return(-1);      // Nur (, - oder Operand
if(k==105) iq=1; else iq=0;                 // Klammerzähler vorbesetzen
for(i=1; i<=ii; i++) {                        // Folgende Zeichen prüfen
  if((j=icode[i])==105) { if (k<100) return(-1); iq+=1; }
  else if(j==106) { if(k>=100 && k!=106) return(-1); iq-=1; }
  else if(j==100) { if(k>=100 && k<=105) icode[i]=104; }
  else if(j>100) { if(k!=106 && k>=100) return(-1); }
  else if(j<100) { if(k!=106 && k<100) return(-1); }
  k=j;
}
if(icode[0]==100) icode[0]=104;       // Erstes Zeichen unitäres Minus ?
if(j!=106 && j>=100) return(-1);               // Letztes Element prüfen
if(iq!=0) return(-1);                          // Klammer-Balance testen
iq=ir=0;                                       // UPN-Conversion starten
ip=it=-1;
for(i=0; i<=ii; i++) {
  if((k=icode[i])<100) ipol[++ip]=k;                         // Operand
  else {                                                     // Operator
    if(k==105) iq+=10;


      else if(k==106) iq-=10;
      else {
      ir=iop_rank[k-100]+iq;
      while(ir<=iranks[it] && it>=0) ipol[++ip]=itmp[it--];
      itmp[++it]=icode[i]; iranks[it]=ir;
      }
    }
  }
  while(it>=0) ipol[++ip]=itmp[it--];
  is=-1;                                               //**** BERECHNUNG
  for(i=0; i<=ip; i++) {
    if((k=ipol[i])<100) stack[++is]=fcode[k];
    else switch(k) {
      case 100: is--; stack[is]=stack[is]-stack[is+1]; break;       // -
      case 101: is--; stack[is]=stack[is]+stack[is+1]; break;       // +
      case 102: is--; stack[is]=stack[is]*stack[is+1]; break;       // *
      case 103: is--; stack[is]=stack[is]/stack[is+1]; break;       // /
      case 104: stack[is]=-stack[is]; break;           // unitäres Minus
      default: return(-1);
    }
  }
  *x=stack[is];
  return(0);
}
//-----------------------------------------------------------------------
// Hauptprogramm für den Taschenrechner
//-----------------------------------------------------------------------
int main()
{
  double x;
  char str[80];
  printf("\n\nTASCHENRECHNER\n");
  printf("Beenden mit CONTROL C\n\n");
  for(;;) {
    printf("\nEingabe: ");
    scanf("%s",str);
    if(calc(&x,str)<0) printf("FEHLER\n");
    else printf("Ergebnis: %f\n",x);
  }
  return(0);
}
« Last Edit: November 27, 2010, 06:03:47 pm by stummel »
Logged

Rotten

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #466 on: November 27, 2010, 08:59:07 pm »

Does anyone know of some good libraries for C++ for creating ASCII games besides Curses and it's siblings? PDCurses absolutely refuses to install on my system now (turns out having 5+ partial installs is a bad thing! Who knew?), and I never got my original install to work again after it crapped out and refused to let me compile half-way through a project (compiled fine a few times, then suddenly didn't work).
Logged
True, but at a certain velocity the resulting explosion expels invader-bits at fatal speeds. You don't want to be dropping trogdolyte-shaped shrapnel bombs into your boneworks.
Only in Dwarf Fortress...

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #467 on: November 27, 2010, 09:56:04 pm »

OpenGL can be good enough, if you want to write all of the code required for drawing the letters, taking input, opening a window, and loading the font(s) yourself. It does allow really advanced effects... (and it's probably already available, on some systems)
Logged
Eh?
Eh!

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #468 on: November 27, 2010, 11:19:11 pm »

I've been trying to figure out how to code artificial neural networks for a while now, however, I seem to have reached an impasse when it comes to full understanding of how they operate and thus how to implement them correctly.

I know about their basic structure and such, but I can't seem to figure out how to make everything fit together to come up with the results I'm aiming for. The main things I need to know are how I should update the weights and how to figure out whether the neural network's structure itself is causing misclassification by having too many/too few nodes and/or connections. Supervised backpropagating errors to update weights pretty much makes sense, but I also keep reading about unsupervised implementations which use activity of nodes themselves to update the weights of the connections. Can anyone explain how these work, or at least post a link to a good source explaining it?
Logged

Berserker

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #469 on: November 28, 2010, 06:50:36 am »

Does anyone know of some good libraries for C++ for creating ASCII games besides Curses and it's siblings? PDCurses absolutely refuses to install on my system now (turns out having 5+ partial installs is a bad thing! Who knew?), and I never got my original install to work again after it crapped out and refused to let me compile half-way through a project (compiled fine a few times, then suddenly didn't work).

Have you tried Libtcod?

That's currently the best library I know for making ASCII games.
Logged

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #470 on: November 28, 2010, 01:07:07 pm »

@alway:
I would suggest you dive into reading some academic papers on the subject, because ANNs aren't really used in the game industry, so it's doubtful that there'll be any material other than them out there explaining how they work. Remember, they're actually rarely used for general-purpose intelligences. If you take a look at http://www.peltarion.com/doc/index.php?title=Applications_of_adaptive_systems, you'll notice that simple neural networks are generally not applied to intelligence: you'll need something more complex.

You may want to look into preexisting codebase like Flood for Perceptrons (http://www.cimne.com/flood/) or NEAT (http://www.cs.ucf.edu/~kstanley/neat.html). They usually have many links to academic papers.
Logged

Rotten

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #471 on: November 28, 2010, 05:43:14 pm »

Does anyone know of some good libraries for C++ for creating ASCII games besides Curses and it's siblings? PDCurses absolutely refuses to install on my system now (turns out having 5+ partial installs is a bad thing! Who knew?), and I never got my original install to work again after it crapped out and refused to let me compile half-way through a project (compiled fine a few times, then suddenly didn't work).

Have you tried Libtcod?

That's currently the best library I know for making ASCII games.
Never tried it, but checking it out right now.
Edit: Holy ****, it looks amazing.
« Last Edit: November 28, 2010, 05:48:15 pm by Rotten »
Logged
True, but at a certain velocity the resulting explosion expels invader-bits at fatal speeds. You don't want to be dropping trogdolyte-shaped shrapnel bombs into your boneworks.
Only in Dwarf Fortress...

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #472 on: December 02, 2010, 01:47:02 pm »

Ronnie decided to take a crack at midpoint displacement again. I've got a fine algorithm that places various points rather nicely.
Code: [Select]
//Same thing I had last time
displace (float offset,   // the height offset, a fraction
          point a, point b) {
  point new_point.x = dist (a,b) / 2;
  new_point.y = random % 100 * offset; //assuming the image height is 100
  draw(new_point);
  displace (offset / 2, a, new_point);
  displace (offset / 2, new_point, b);
}
Now, say instead of drawing the points it saves them in a list, I get something like so:
1, 6, 4, 7, 3, 8, 5, 9, 2 (the points in order, each number corresponds to the point's position in the list-- They're sorted in the order they've been drawn)
How do I sort them so the 2nd point in list is really the 2nd point, and not the 2nd point drawn.

e, I knew I forgot something, pretend the above function terminates at some point, and doesn't recurs forever.
« Last Edit: December 02, 2010, 02:31:32 pm by ILikePie »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #473 on: December 02, 2010, 03:47:13 pm »

I'm confused to what you mean as "really the second point". The order you just gave looks good to me (for a 1D heightmap).
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #474 on: December 02, 2010, 03:59:50 pm »

the point marked as 2 in my list is the last point on the line (The numbers now refer to the order in which the points are drawn, not where they are on line):
1 6 4 7 3 8 5 9 2
o o o o o o o o o
I want the bold 'o' to be marked as 2 instead. Anyway, I think I've got it, I can fill them in as I go on.

Now for a different issue, I'm writing this in Java, I keep getting this annoying error:
Code: [Select]
javac main.java
main.java:1: '{' expected
class RGB () {
         ^
THE CODE:
class RGB () {
    private int red;
    private int green;
    private int blue;

    public int get_red() {
    return red;
    }
    public int get_green() {
    return green;
    }
    public int get_blue() {
    return blue;
    }
}
Any ideas? It's not the class name, I've tried changing it to something random and I still get the error.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #475 on: December 02, 2010, 04:09:31 pm »

the point marked as 2 in my list is the last point on the line (The numbers now refer to the order in which the points are drawn, not where they are on line):
1 6 4 7 3 8 5 9 2
o o o o o o o o o
I want the bold 'o' to be marked as 2 instead. Anyway, I think I've got it, I can fill them in as I go on.
Yeah, that's what I thought, but that solution seemed too simple :)

Quote
Now for a different issue, I'm writing this in Java, I keep getting this annoying error:
try:
class RGB { } ;)
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #476 on: December 02, 2010, 04:24:26 pm »

Oh, how silly of me. Thanks. ]-:
Anyway, this porting stuff is harder than I thought. What the equivalent of c's unsigned char in Java (1 byte in length, from 0 to 255)? The closest I've got is 'byte', but it goes from -128 to 128.

Also, constructor issues, it'll take a while before I get how this works:
Code: [Select]
main.java:26: cannot find symbol
symbol  : constructor RGB(int,int,int)
location: class RGB
    private RGB[] data = new RGB(0, 0, 0)[hght*widt];
                       ^

RGB's constuctor
public RGB (byte r, byte g, byte b) {
    red = r;
    green = g;
    blue = b;
}
If I understand correctly, it says RGB's constructor takes ints, but really, it takes bytes (Maybe it sees the zeros as ints? I don't know).
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #477 on: December 02, 2010, 04:34:59 pm »

I'm guessing you can't assign an instance to an array of that instance, but have to add it? I really don't know anything about java. :)
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #478 on: December 03, 2010, 02:34:23 am »

you want an array filled many times with one RGB(0,0,0) object?

that syntax will not work, do it by hand.

also, if RGB.r wasn't static, that could easily be an error.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #479 on: December 03, 2010, 04:23:51 am »

Funny, you're doing the same thing as my daughter: Using existing "grammar" on stuff that wasn't meant to be grammared (see what I did there) that way. This morning she said "I'm happy at you". As happy is the opposite of angry (in her mind), and as it's "angry at you", you should be able to apply those rules ("at you") to "happy" as well.

Same thing here, I think you're trying to use syntax that you never learned, but just made up. Maybe I'm bad at making up syntax, but doing that almost never works for me (in programming languages).
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))
Pages: 1 ... 30 31 [32] 33 34 ... 78