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 ... 27 28 [29] 30 31 ... 78

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

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #420 on: October 26, 2010, 05:58:06 pm »

Thank you for the code post, Argembarger.
My eyes will have fun cutting through it with machetes and having a general sense of confusion.

Inform 7 seems amazing, but I can't figure out how to stack if statements.
If anyone wants to show me a working example of a three level deep if statement, I'd be very very grateful.

C++ example:
Code: [Select]
if(a==1){
   if(b==1){
      if(c==1){
          //blah
      }
   }
}

VB code:
Code: [Select]
if a = 1 then
     if b = 1 then
          if c = 1 then
             'blah
          end if
     end if
end if

Inform 7 code:
Code: [Select]
if the man has a sword then
     huh?

What I really don't want is any AND logic.
I can do AND just fine.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Mondark

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #421 on: October 26, 2010, 07:47:40 pm »

Inform 7 seems amazing, but I can't figure out how to stack if statements.

I haven't really had to do this very much, since I can usually get the same result in a cleaner way by using scenes and rules, but I think you can use the 'begin' and 'end if' keywords to do this.

Code: [Select]
if [some condition] begin;
  if [other condition] begin;
  end if;
end if;
Logged
Fefeshnelmargalip

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #422 on: October 26, 2010, 09:06:04 pm »

Sounds good.
I'll report back the results.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

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 #423 on: October 26, 2010, 10:57:31 pm »

Or you might need to use a colon at the end of the if statement. It's been a long time since I looked at it, though.
Logged
Eh?
Eh!

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #424 on: October 28, 2010, 08:04:24 am »

This game is notable in that it has the worst fucking gameplay ever. Just spam l until you find a goblin then spam k until it's dead. Rinse, repeat.

so it's a text based god of war then.
Logged

alfie275

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #425 on: October 30, 2010, 10:28:34 am »

Talking of Inform, I have the source to this story I started but never finished, if you want to dig through it for any useful crap:

Spoiler (click to show/hide)
Logged
I do LP of videogames!
See here:
http://www.youtube.com/user/MrAlfie275

Mondark

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #426 on: October 30, 2010, 04:20:22 pm »

Nice Dr. Who setup there!  I like the idea of going into the broken down, future version of the shed to get the key that unlocks the past (unlooted) version.  It's a nice usage of the regions mechanism.
Logged
Fefeshnelmargalip

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #427 on: October 31, 2010, 07:40:25 am »

What would this do?

Code: [Select]
int main()
{
int naArray[1];
int nSize = 0;
do
{
naArray[nSize++] = 424242;
} while (nSize > 0);
return 0;
}
Logged

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 #428 on: October 31, 2010, 09:27:29 am »

That would probably segfault.


Because it is a do while loop, the size variable would be increased first, so it would repeat. It might overwrite the size variable itself, or it might not, but either way it would start writing somewhere it shouldn't. Unless it was carefully engineered to affect a specific memory location to do something useful, and in that case it would probably qualify as an IOCCC entry with little additional work.
Logged
Eh?
Eh!

ILikePie

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

I've tried messing around with bits today. Doing decimal to binary conversion, addition, etc.
Here's the addition function, which seems to break when calculating various numbers. 15 + 9 = 32, 15 + 15 = 128, 15 + 11 = 64, etc. (I've only noticed this happening with 15)
Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#define BITS 8

int b_add (int left, int rght) {
  int ans[BITS],    // answer
    dec = 0,            // decimal value
    car = 0,        // carry
    l_bit,          // left bit
    r_bit,          // right bit
    i = 0,          // iterators:
    j = 1;          //
  // calculate:
  for (; i <= BITS-1; i++) {
    l_bit = (left & j) >> i;
    r_bit = (rght & j) >> i;
    j = j << 1;
    printf("l: %d  r: %d\n", l_bit, r_bit);
    if (car > 0 && l_bit == 0) {
      l_bit = 1;
      car--;
    }
    if (l_bit == 1) {
      if (r_bit == 1) {
        car++;
        ans[i] = 0;
      } else {
        ans[i] = (car > 0)? 0:1;
      }
    } else {
      ans[i] = l_bit | r_bit;
    }
  }
  // convert:
  i = 0;
  for  (; i <= BITS-1; i++) {
    dec = dec | (ans[i] << i);
  }
  // print:
  printf("result: ");
  i = BITS-1;
  for (; i >= 0; i--) {
    printf("%d", ans[i]);
  }
  printf(" -> %d\n", dec);
}
What baffles me though, is not what causes this (It's obviously the broken pseudo-carry), but why does it happen. Hopefully someone has the answer.

ps: the carry is broken because I tried writing this without looking at some solution, I didn't even know how to add when I started. instead of having left OR right OR carry, I have carry as the amount of times I still need to carry, then if left = 0, make it equal 1 and carry--.
« Last Edit: November 01, 2010, 02:42:46 pm by ILikePie »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #430 on: November 01, 2010, 07:26:55 pm »

Code: [Select]
    if (car > 0 && l_bit == 0) {
      l_bit = 1;
      car--;   // here left = 1, carry becomes 0
    }


    if (l_bit == 1) {
      if (r_bit == 1) {
        car++;
        ans[i] = 0;
      } else {   // so if right =0 we end up here
        ans[i] = (car > 0)? 0:1; // What is this? We already used the carry to add to "left" I think this is breaking it.
      }
    } else {
      ans[i] = l_bit | r_bit;
    }
  }
}

Possible fix:
if (car > 0 && l_bit == 0) {
  l_bit = 1;
  car--;   // here left = 1, carry becomes 0
}
ans[i] = l_bit | r_bit;
if(l_bit && r_bit){ car++; }
But it's late and I might be mistaken.
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))

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #431 on: November 01, 2010, 09:45:36 pm »

Thank you for the inform code Alfie.
I couldn't figure out the syntax for some things so I copied some of yours.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

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 #432 on: November 01, 2010, 10:17:55 pm »

Here is an old one of mine from about a year ago. I started by trying to create a basic computer system that would be used as a major plot component. Unfortunately, I stopped, possibly because of laziness, possibly because of some difficult bit.
Spoiler (click to show/hide)

Yeah, it looks like I just quit in the middle of working on it, but there should be plenty of example syntax there.
Logged
Eh?
Eh!

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #433 on: November 04, 2010, 11:45:20 am »

That is all very interesting.

I've started a side project.
It will be crispy.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Argembarger

  • Bay Watcher
    • View Profile
    • Not quite yet
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #434 on: November 05, 2010, 11:01:47 am »

Woo I finally put the final touches to my Enigma encrypter/decrypter!

Err, I mean

j6`8   }   
@D H
N#&(V+'Y'4\,('.#c)3)9A9>0>|243CKCH:Hx
Logged
Quote from: penguinofhonor
Quote from: miauw62
This guy needs to write a biography about Columbus. I would totally buy it.
I can see it now.

trying to make a different's: the life of Columbus
Pages: 1 ... 27 28 [29] 30 31 ... 78