What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Shorter code for this? :S

Shorter code for this? :S
Author: Message:
albert
Veteran Member
*****

Avatar

Posts: 2247
Reputation: 42
– / Male / Flag
Joined: Feb 2005
O.P. Shorter code for this? :S
I have a little problem with this code.

Basicly it's a array (I think that's how it's called in english, in french it's tableau, well it's some kind of table for programming that you can put date in..)

Anyhow, I'm doing this Othello game, and I'm quite sure there's an easier way to code this, but I can't seem to find a solution.

Here's the current code :

code:
for ( compteurColonnes = 0 ; compteurColonnes < 10 ; compteurColonnes ++ )
            for ( compteurRangees = 0 ; compteurRangees < 10 ; compteurRangees ++)
                othellier[compteurColonnes][compteurRangees]= '~' ;
       
        othellier[0][0]= ' ' ;
        othellier[0][1]= 'A' ;
        othellier[0][2]= 'B' ;
        othellier[0][3]= 'C' ;
        othellier[0][4]= 'D' ;
        othellier[0][5]= 'E' ;
        othellier[0][6]= 'F' ;
        othellier[0][7]= 'G' ;
        othellier[0][8]= 'H' ;
        othellier[0][9]= ' ' ;
       
        othellier[9][0]= ' ' ;
        othellier[9][1]= 'A' ;
        othellier[9][2]= 'B' ;
        othellier[9][3]= 'C' ;
        othellier[9][4]= 'D' ;
        othellier[9][5]= 'E' ;
        othellier[9][6]= 'F' ;
        othellier[9][7]= 'G' ;
        othellier[9][8]= 'H' ;
        othellier[9][9]= ' ' ;
       
        othellier[0][0]= ' ' ;
        othellier[1][0]= '1' ;
        othellier[2][0]= '2' ;
        othellier[3][0]= '3' ;
        othellier[4][0]= '4' ;
        othellier[5][0]= '5' ;
        othellier[6][0]= '6' ;
        othellier[7][0]= '7' ;
        othellier[8][0]= '8' ;
        othellier[9][0]= ' ' ;
       
        othellier[0][9]= ' ' ;
        othellier[1][9]= '1' ;
        othellier[2][9]= '2' ;
        othellier[3][9]= '3' ;
        othellier[4][9]= '4' ;
        othellier[5][9]= '5' ;
        othellier[6][9]= '6' ;
        othellier[7][9]= '7' ;
        othellier[8][9]= '8' ;
        othellier[9][9]= ' ' ;


the code is in java, but i think anyone with a little programming skills can understand it

and i have tried making a few "for"s with the numbers.. but the problem is that the array in "char" since I have to represent black by * and white by -

so.. yeah,.. anyhelp would be appreciated.
02-11-2007 04:16 PM
Profile E-Mail PM Web Find Quote Report
Jesus
Scripting Contest Winner
****

Avatar
Koffie, my cat ;)

Posts: 623
Reputation: 15
38 / Male / Flag
Joined: Jul 2005
RE: Shorter code for this? :S
well, IIRC, this code:
code:
othellier[0][0]= ' ' ;
othellier[0][1]= 'A' ;
othellier[0][2]= 'B' ;
othellier[0][3]= 'C' ;
othellier[0][4]= 'D' ;
othellier[0][5]= 'E' ;
othellier[0][6]= 'F' ;
othellier[0][7]= 'G' ;
othellier[0][8]= 'H' ;
othellier[0][9]= ' ' ;

othellier[9][0]= ' ' ;
othellier[9][1]= 'A' ;
othellier[9][2]= 'B' ;
othellier[9][3]= 'C' ;
othellier[9][4]= 'D' ;
othellier[9][5]= 'E' ;
othellier[9][6]= 'F' ;
othellier[9][7]= 'G' ;
othellier[9][8]= 'H' ;
othellier[9][9]= ' ' ;
can be replaced with this
code:
othellier[0]=new Array(' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', ' ');
othellier[9]=new Array(' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', ' ');

not too sure though...

does your own code work?
02-11-2007 04:29 PM
Profile PM Find Quote Report
albert
Veteran Member
*****

Avatar

Posts: 2247
Reputation: 42
– / Male / Flag
Joined: Feb 2005
O.P. RE: Shorter code for this? :S
Jesus, thanks for the help but shawnz has given me a good idea

put the labels outside the array.

Should fix it. :)
02-11-2007 04:34 PM
Profile E-Mail PM Web Find Quote Report
vikke
Senior Member
****

Avatar

Posts: 900
Reputation: 28
31 / Male / Flag
Joined: May 2006
RE: Shorter code for this? :S
I don't know Java but you could do:
code:
var Alph = " ABCDEFGH";
for(var i;i=0;i<Alph.length){
    othellier[0][i] = Alph.charAt(i);
    othellier[9][i] = Alph.charAt(i);
}

etc.

Edit: removed smileys from post which would appear in the code sample

This post was edited on 02-11-2007 at 05:57 PM by vikke.
02-11-2007 05:56 PM
Profile E-Mail PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: Shorter code for this? :S
code:
String Alph = " ABCDEFGH";
for(int i; i = 0; i < Alph.length){
    othellier[0][i] = Alph.charAt(i);
    othellier[9][i] = Alph.charAt(i);
}
:P
var doesn't exist in Java.

This post was edited on 02-11-2007 at 09:55 PM by RaceProUK.
[Image: spartaafk.png]
02-11-2007 09:53 PM
Profile PM Web Find Quote Report
vikke
Senior Member
****

Avatar

Posts: 900
Reputation: 28
31 / Male / Flag
Joined: May 2006
RE: Shorter code for this? :S
I said I didn't know java :).
02-12-2007 11:16 AM
Profile E-Mail PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: Shorter code for this? :S
I know, but hopefully you know a tiny bit of it now ;)
[Image: spartaafk.png]
02-13-2007 04:59 PM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On