[computer-go] Re: C in Java
Chrilly
c.donninger at wavenet.at
Mon Jul 24 06:24:35 PDT 2006
> Very interesting. Can you provide sample code of writing C style program
> using Java?
>
> Weimin
>
/***********************************************************************/
/* Pushes capture-move in the quiesence search on Move-Stack. */
/***********************************************************************/
final static void CapLinkMv(int from,int to,int flgs) {
int score;
if(TmpStackTop<MVSTACKSZ) { /* Check for Move-Stack-Overflow */
score=0;
if(flgs!=0) {
score=CapBonus[Board[to]]-OwnMalus[Board[from]];
}
MvStack[TmpStackTop]=(score<<SCRENP_SHFT)|(flgs<<FLGS_SHFT)|(to<<TO_SHFT)|from;
TmpStackTop++;
}
}
This code shows 2 points: The method/function definition to avoid a dynamic
method invocation.
final static void CapLinkMv(int from,int to,int flgs) {
Packing of a structure in an int.
MvStack[TmpStackTop]=(score<<SCRENP_SHFT)|(flgs<<FLGS_SHFT)|(to<<TO_SHFT)|from;
This packing is in general not necessary. Only when one wants to save RAM.
In this case the original code had to fit into 4KByte of RAM and was written
very tight.
But its probably nevertheless faster than storing the 4 members into 4 int
arrays and its certainly faster then replacing the structure with a class.
Especially small classes have a big overhead.
I think the most annoying part of Java is that its trivial to
Reverse-Engineer the code. Every code can be reverse-engineered, but
Reverse-Engenieering e.g. a Chess/Go engine in an exe or dll is a hard job.
Reverse engineering an exe is in my view a "fair" trade. The reverser has to
invest a lot of effort and skills and gets some information. It would be
probably better to spent the effort on his own programm. But in case of a
Java programm its too easy. Its unfair to the original writer. E.g. I would
Reverse a Jave version of Handtalk. But Reverse-Engineering the .exe is too
hard work and no hobby anymore.
Best Regards
Chrilly
More information about the computer-go
mailing list