Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 395 396 [397] 398 399 ... 796

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

Arx

  • Bay Watcher
  • Iron within, iron without.
    • View Profile
    • Art!
Re: if self.isCoder(): post() #Programming Thread
« Reply #5940 on: June 04, 2014, 01:32:38 am »

Spoiler: Originally (click to show/hide)

I figured it out. There was some strangeness with permissions, fixed by adding

grant {
    permission java.net.SocketPermission "localhost:1527", "listen,resolve";
};

to the java.policy file. Now I can get stuck on different parts of the project.
« Last Edit: June 04, 2014, 03:25:42 am by Arx »
Logged

I am on Discord as Arx#2415.
Hail to the mind of man! / Fire in the sky
I've been waiting for you / On this day we die.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5941 on: June 04, 2014, 07:16:30 am »

There's a cool challenge, the 1kb roguelike. In that, you make a roguelike but your source code must be no greater than 1024 characters. It's a good learning challenge for efficient coding, and you'd be amazed how much stuff you can actually jam in their if you really try.

I made an entry.
Code: (Perl) [Select]
sub i($){int rand shift}sub v{$m[i @m]=~s/$_[1]/$_[2]/ for 0..$_[0]}@w=0..40;@h=0..22;@s=0..942;
@z=join("",map {'@+@.@..@&..&1..1@2@1@1@.&3@.&1&.3&.@1&.&1@1@@*.&&*.&@>.>'=~s/(\d)/$1+$_/erg}4,3,2,1,0)=~m/..../g;
m/(..)(.)(.)/,$y{$1}=[$2,$3]for@z;$e=4;D:{@r=@m=(".")x(@w*@h);for(0..8){$i=2+i 30;$j=3+i 12;$l=3+i 4;
for$a(0..$l){for$b(0..$l){$m[$a+$i+@w*($b+$j)]=~s/./$a*$b*($a-$l)*($b-$l)?",":"#"/e}}}v($e,'\.',$_),v(9*$e,',',$_)for 1..5;
v(30,',','*');v(99,'#','+');$m[$_]=" "for@w;$m[@w*$_-1]="\n"for@h;$m[$_]=~s/,/./for@s;$m[@w]='@';
$m[-2]=">";$l=20;do{$t++;$c=942+2*i 2;for$k(0..$#m){$p=$c*$k%@m;$d=($p+($m[$p]=~/[@&]/?/d/-/a/+@w*(/s/-/w/):i(3)-42+41*i 3))%@m;
$r[$p]!=$t and$n=$y{$m[$p].$m[$d]}and($m[$d]eq'>'?{$e+=4,redo D}:$m[$d]eq'@'?$l--:($r[$d]=$t,@m[$p,$d]=@$n));}
$e=4,next if$l<=0;print@m,"LV:$e HP:$l >";}while(<STDIN>)}
828 bytes (not counting the newlines) of Perl, so theoretically I could still add a lot of game mechanics. Since I used no modules, you'll need to press Return after every WASD command. Goal: See how many times you can get to the exit without dying. It gets harder. Also there's treasure in the buildings.
If it doesn't want to run, try adding a line of "#!/usr/bin/perl" at the beginning of the program, or running it as "perl filename.pl" in a shell.
Logged

Maklak

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5942 on: June 04, 2014, 10:15:45 am »

That looked to ridiculous not to see what it does, so I've run it and:

Bareword found where operator expected at game.pl line 2, near "s/(\d)/$1+$_/erg"
syntax error at game.pl line 2, near "s/(\d)/$1+$_/erg"
Execution of game.pl aborted due to compilation errors.

I think, I've copied it correctly, so maybe perl 5.6 doesn't like it for some reason. Oh well, it is so obfuscated that I won't even try to figure out the error.
Logged
Quote from: Omnicega
Since you seem to criticize most things harsher than concentrated acid, I'll take that as a compliment.
On mining Organics
Military guide for FoE mod.
Research: Crossbow with axe and shield.
Dropbox referral

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5943 on: June 04, 2014, 12:00:23 pm »

You have Perl 5.6? In that case, no wonder it doesn't work. The /r substitution modifier was only introduced in 5.10. Try upgrading your Perl and running it again. If you can't or don't want to upgrade, replace line 2 with this:
Code: [Select]
@z=join("",map {($A='@+@.@..@&..&1..1@2@1@1@.&3@.&1&.3&.@1&.&1@1@@*.&&*.&@>.>')=~s/(\d)/$1+$_/eg;$A}4,3,2,1,0)=~m/..../g;
Logged

Maklak

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5944 on: June 04, 2014, 12:51:52 pm »

I installed perl 5.6 with MinGW a while ago and it stayed. I may be upgrading this computer soon, so I don't feel like upgrading the software. Plus perl 5.6 works well enough for my needs, even though I miss on a few features like switch statements, // defined-or and so on.

Huh, I'm chasing numbers with "@" and they go lower when I catch them.
Code: [Select]
..................2.....................
........................................
.......................####+#####.......
.......................#..#.....#.......
.......................#..#..5.5#.......
..............1@.......####.....#.......
.......................#.2#.4...#....1..
..........5............#..#4.3..#......5
.4......#+#####........###+###+##.2.....
........#.....+..##++###.....3..........
........#.3.5.#..#3#####................
........#.....#5.#.##+##..............4.
........#.....+..#2#..#######...........
........#2....#..#.#..#.1...####+#......
........#######..#.#52#.....#.5..#......
..2..............+###+#.2...#51.2#......
......................#.....#..5.#......
................1.....+...22#3...#......
......................######+#####......
.............3..........................
......1.................................
.......................................>
LV:4 HP:18 >a
Logged
Quote from: Omnicega
Since you seem to criticize most things harsher than concentrated acid, I'll take that as a compliment.
On mining Organics
Military guide for FoE mod.
Research: Crossbow with axe and shield.
Dropbox referral

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #5945 on: June 05, 2014, 04:04:25 am »

There's a cool challenge, the 1kb roguelike. In that, you make a roguelike but your source code must be no greater than 1024 characters. It's a good learning challenge for efficient coding, and you'd be amazed how much stuff you can actually jam in their if you really try.

I made an entry.
Code: (Perl) [Select]
sub i($){int rand shift}sub v{$m[i @m]=~s/$_[1]/$_[2]/ for 0..$_[0]}@w=0..40;@h=0..22;@s=0..942;
@z=join("",map {'@+@.@..@&..&1..1@2@1@1@.&3@.&1&.3&.@1&.&1@1@@*.&&*.&@>.>'=~s/(\d)/$1+$_/erg}4,3,2,1,0)=~m/..../g;
m/(..)(.)(.)/,$y{$1}=[$2,$3]for@z;$e=4;D:{@r=@m=(".")x(@w*@h);for(0..8){$i=2+i 30;$j=3+i 12;$l=3+i 4;
for$a(0..$l){for$b(0..$l){$m[$a+$i+@w*($b+$j)]=~s/./$a*$b*($a-$l)*($b-$l)?",":"#"/e}}}v($e,'\.',$_),v(9*$e,',',$_)for 1..5;
v(30,',','*');v(99,'#','+');$m[$_]=" "for@w;$m[@w*$_-1]="\n"for@h;$m[$_]=~s/,/./for@s;$m[@w]='@';
$m[-2]=">";$l=20;do{$t++;$c=942+2*i 2;for$k(0..$#m){$p=$c*$k%@m;$d=($p+($m[$p]=~/[@&]/?/d/-/a/+@w*(/s/-/w/):i(3)-42+41*i 3))%@m;
$r[$p]!=$t and$n=$y{$m[$p].$m[$d]}and($m[$d]eq'>'?{$e+=4,redo D}:$m[$d]eq'@'?$l--:($r[$d]=$t,@m[$p,$d]=@$n));}
$e=4,next if$l<=0;print@m,"LV:$e HP:$l >";}while(<STDIN>)}
828 bytes (not counting the newlines) of Perl, so theoretically I could still add a lot of game mechanics. Since I used no modules, you'll need to press Return after every WASD command. Goal: See how many times you can get to the exit without dying. It gets harder. Also there's treasure in the buildings.
If it doesn't want to run, try adding a line of "#!/usr/bin/perl" at the beginning of the program, or running it as "perl filename.pl" in a shell.
That's absolutely awesome.

I'm currently working on a roguelike - not for any competition or anything - and the code is approaching the 50Kb mark. Not counting the 60~ Kb library I'm using.
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.

Teneb

  • Bay Watcher
  • (they/them) Penguin rebellion
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5946 on: June 05, 2014, 11:00:59 am »

Could someone explain to me what is causing this bug? I've been at it for days now and have had no luck. I don't know too much about generic types in java, so I guess I have no option but to ask.

Bug:
Code: [Select]
constructor OperacaoBinaria in class OperacaoBinaria<T1,T2,R> cannot be applied to given types;
required: Expressao<Escalar>,Expressao<Escalar>
found: no arguments
reason actual and formal argument lists differ in length
where T1,T2,R, are type-variables:
T1 extends Expressao declared in class OperacaoBinaria
T2 extends Expressao declared in class OperacaoBinaria
R extends Expressao declared in class OperacaoBinaria

Here are the relevant classes (don't mind the names in portuguese):
Spoiler (click to show/hide)
Logged
Monstrous Manual: D&D in DF
Quote from: Tack
What if “slammed in the ass by dead philosophers” is actually the thing which will progress our culture to the next step?

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5947 on: June 05, 2014, 03:55:15 pm »

Your problem has nothing to do with templates and generic types, you're simply using the "super" keyword wrong.

Here's how to fix your problem:
Code: [Select]
package operador.de.matrizes;

public class AdicaoEscalar extends OperacaoBinaria<Expressao<Escalar>,Expressao<Escalar>,Escalar>{
    public AdicaoEscalar(Expressao<Escalar> arg1, Expressao<Escalar> arg2){
        super(arg1,arg2);
    }
    public Expressao<Escalar> calcular(){
        return null;
    }
}

Detailed explanation: To access arg1 and arg2 in AdicaoEscalar, you don't write super.arg1, but this.arg1 (or simply arg1). The actual purpose of super is to call a parent class's constructor or methods, and here's why it's necessary: To construct a derived class, Java needs to call the parent class constructor before the derived class constructor. Usually that's always the default zero-argument constructor, but if the parent class doesn't have a zero-argument constructor (or if you don't want to use that one), your derived class constructor has to specify the preferred constructor itself, by making the very first line of the derived constructor a call to super(...) with the appropriate arguments. In this case super(arg1, arg2) is just another name for the constructor OperacaoBinaria(arg1, arg2).
Logged

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5948 on: June 06, 2014, 07:53:00 am »

Anyone knows what's wrong with this piece of Matlab code? It's outputting nonsense as I can manually find a vector that actually intersects with the rectangle but the program isn't adding it up. If it did, then it should show up in the prob even if it's 1/300000.

Code: [Select]
function [prob, P] = MCProbSeq(d, alpha, dir)
%MCPROBSEQ Generates the probability of hitting a rectangular target
% at a given distance d with apex angle alpha, the axis of the cone
% pointing at direction of vector dir, with a Monte Carlo method.
% The random direction is assumed to be uniformly distributed within the
% cone.

dist = [0 0 d]';

a = dir/sqrt(sum(dir.^2));%Unit vector
phi = acos(dot(a, [0 0 1]'));
if alpha >= pi
    error('Apex angle too big');
elseif d < 0
    error('d must be positive scalar')
end

if (pi/2 < phi < 3*pi/2 && d == 0) %Point blank range
    prob = 1;
    return
end


%Rectangular approximation based on a person with 1.8 m height.
len = 1.8;
wid = 0.88/1.8;

apex = alpha/2;
n = [0 0 1]';%Normal vector of the plane
%Using p_0 = [0 0 0]'

A = null(a');
u = A(:,1);%Orthogonal unit vectors
v = A(:,2);


samples = 300000;

t = 2*pi*rand(samples,1);%Uniform distribution
z = cos(apex) + (1-cos(apex))*rand(samples,1);%Uniform distribution
P = [sqrt(1-z.^2).*cos(t) sqrt(1-z.^2).*sin(t) z];%Uniform distribution
count = 0;
for i=1:samples
    P(i,:) = (P(i,1)*u + P(i,2)*v + P(i,3)*a)';
    if dot(P(i,:)', n) ~= 0 %Is the line parallel?
        k = dot(-dist, n)/dot(P(1,:),n);
        if k >= 0 %Is it pointing at it?
            point = k*P(1,:)' + dist;
            if abs(point(1,1)) <= len/2 && abs(point(2,1)) <= wid/2
                %Is the point on the rectangle?
                count = count + 1;
            end
        end
    end
end

prob = count/length(P(:,1));

end


Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5949 on: June 06, 2014, 08:33:25 am »

Your gun is pointing the wrong way.
Code: (Faulty) [Select]
        k = dot(-dist, n)/dot(P(1,:),n);
Code: (Fixed) [Select]
        k = dot(dist, n)*dot(P(i,:),n);
Note that I replaced the 1 with an i, that happens two lines later too:
Code: (Faulty) [Select]
            point = k*P(1,:)' + dist;
Code: (Fixed) [Select]
            point = k*P(i,:)' + dist;
Logged

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5950 on: June 06, 2014, 08:40:50 am »

GAH, those tiiiny typos ruin everything, don't they? Thanks!  :D
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5951 on: June 06, 2014, 08:47:25 am »

In you guys' opinions, do you think these files are OK?

utility.h,utility.cpp,utility.tpp

Basically, I have a few functions and global variables that are handy to have, so I include them everywhere. I'm not quite sure it's good programming though >_> There's an unfortunate side effect of including the number of #includes by a lot each time it is #include'd. The tpp file is because C++ is stupid and doesn't support templates being in cpp files. :I
« Last Edit: June 06, 2014, 09:09:05 am by Skyrunner »
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5952 on: June 06, 2014, 09:07:06 am »

In you guys' opinions, do you think these files are OK?

utility.h,url=https://github.com/Skyyrunner/ChartedWaters/blob/master/ChartedWaters/utility.cpp]utility.cpp,[/url]url=https://github.com/Skyyrunner/ChartedWaters/blob/master/ChartedWaters/utility.tpp]utility.tpp[/url]

We have some utility code where I work. I don't see a problem with it, as long as it doesn't get too wild. We do Django development, so we split our helper code into the apps where said code is used. (Might want to check up on your urls, though)

Something I noticed:
Code: [Select]
std::vector<int> four = { 0, 1, 2, 3 };
std::vector<int> five = { 0, 1, 2, 3, 4, 5 };

Intentional? Based on one through four, five should have five elements.
« Last Edit: June 06, 2014, 09:09:07 am by Mephisto »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5953 on: June 06, 2014, 09:09:53 am »

That is my mistake. Fixed it. xD
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Teneb

  • Bay Watcher
  • (they/them) Penguin rebellion
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5954 on: June 06, 2014, 11:38:38 am »

Your problem has nothing to do with templates and generic types, you're simply using the "super" keyword wrong.

Here's how to fix your problem:
Code: [Select]
package operador.de.matrizes;

public class AdicaoEscalar extends OperacaoBinaria<Expressao<Escalar>,Expressao<Escalar>,Escalar>{
    public AdicaoEscalar(Expressao<Escalar> arg1, Expressao<Escalar> arg2){
        super(arg1,arg2);
    }
    public Expressao<Escalar> calcular(){
        return null;
    }
}

Detailed explanation: To access arg1 and arg2 in AdicaoEscalar, you don't write super.arg1, but this.arg1 (or simply arg1). The actual purpose of super is to call a parent class's constructor or methods, and here's why it's necessary: To construct a derived class, Java needs to call the parent class constructor before the derived class constructor. Usually that's always the default zero-argument constructor, but if the parent class doesn't have a zero-argument constructor (or if you don't want to use that one), your derived class constructor has to specify the preferred constructor itself, by making the very first line of the derived constructor a call to super(...) with the appropriate arguments. In this case super(arg1, arg2) is just another name for the constructor OperacaoBinaria(arg1, arg2).
Thanks for the help, this has been a pain for a few days now and I'm glad it's solved.
Logged
Monstrous Manual: D&D in DF
Quote from: Tack
What if “slammed in the ass by dead philosophers” is actually the thing which will progress our culture to the next step?
Pages: 1 ... 395 396 [397] 398 399 ... 796