aspose file tools*
The moose likes Game Development and the fly likes Java Chess Game I made by my self Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "Java Chess Game I made by my self " Watch "Java Chess Game I made by my self " New topic
Author

Java Chess Game I made by my self

mohamed sami
Greenhorn

Joined: Jun 16, 2007
Posts: 4
This is a link to download a chess game i made by my self , i fact it still 2 players to but it contain server and client side so please check it a replay to me /
Here to download


thanks


Just walk beside me and be my friend <a href="http://www.codemiles.com" target="_blank" rel="nofollow"><b>Java problems</b></a>,<a href="http://www.codemiles.com/viewforum.php?f=109" target="_blank" rel="nofollow"><b>Applet Games</b></a>
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Great Stuff!

I'm working on my next program, my first one is called JChess
JChess

But the second one is graphically better with different themes,
such as wood,metal,grass,marble.
Includes Transposition Table
Basic form of QS
Rotated Bitboards
Iterative Deepening applied with NegaMax
Fairly simple Evaluation Function
A PGN player
Unfortunatly its not 2 player, I haven't figured out how to do it yet.

I tried your JAR file, in the dist folder, but the 1 Player Version
wasn't enabled. Why is this?

Looks good though.
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
i had written a chess engine in c++ four years back.

i feel it's better to code chess engine in c/c++ rather than java. because chess engine is computing oriented and c is faster than java.
Dawei Li
Greenhorn

Joined: Jul 01, 2007
Posts: 22
i had written a chess engine in c++ four years back.
i feel it's better to code chess engine in c/c++ rather than java. because chess engine is computing oriented and c is faster than java.
Yes I think the c++ is very fast.
But Java is more stable,and j2ee is easy to make a large webgame.


<a href="http://www.java-forums.org" target="_blank" rel="nofollow">Java</a>
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by vikas chess:
c is faster than java.


Not necessarily.

It was very true up to version 1.2 of Java. It became less definite with 1.3 and is highly dubious now, with Java 6. HotSpot and GC are now very, very clever.

C programmers think that C's direct access to memory makes it faster. In fact, that can make it slower. Because Java applications cannot work directly with memory, the JVM can move stuff around for optimal performance, or not put it in RAM at all, in a way that C cannot. Also, Java's memory allocation and deallocation can sometimes be faster than C's.

I'm not saying Java is faster than C, or even the same speed. What I am saying is that it is out of date to blindly assume that C is fast and Java is slow.

See this excellent IBM article for fuller, and more authoritative, analysis.
[ July 05, 2007: Message edited by: Peter Chase ]

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
Originally posted by Peter Chase:


Not necessarily.

It was very true up to version 1.2 of Java. It became less definite with 1.3 and is highly dubious now, with Java 6. HotSpot and GC are now very, very clever.

C programmers think that C's direct access to memory makes it faster. In fact, that can make it slower. Because Java applications cannot work directly with memory, the JVM can move stuff around for optimal performance, or not put it in RAM at all, in a way that C cannot. Also, Java's memory allocation and deallocation can sometimes be faster than C's.[ July 05, 2007: Message edited by: Peter Chase ]


for general purpose software development such as banking, finance, accounting etc. java is perfect. java is good choice for web based or client-server based applications. even for games, java is a good choice.

but in case of computing oriented code, c/c++ is still faster than java. for e.g., for some operations assembly code is used in my chess engine to make it faster, which is not possible in java.

applications based on AI technologies such as chess, robotics etc. c/c++ is better choice.

this is the reason why 99% chess engines are written in C/C++
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Hi vikas chess ,

Kindly check with the javaranch's naming policy.I am sure chess is not your last name.

In terms of performance Java has improved a lot from its earlier version.It's JIT takes care of converting heavily used byte codes into native.
I have not done any performance benchmarking on java's speed , but I am sure that if its not faster , then its not much slower also.


Rahul Bhattacharjee
LinkedIn - Blog
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
You know, you can prove anything you wish with statistics.

I would say the reason 99% of chess engines are written in C/C++ is more to do with C/C++ having been around longer.

But as with any system what you gain in one area you lose in another.

apprently WoW makes use of Java *shrugs*
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
Originally posted by vikas chess:
but in case of computing oriented code, c/c++ is still faster than java.

As Peter said, that's a dubious claim to make in general; what is your basis for making it?

for some operations assembly code is used in my chess engine to make it faster, which is not possible in java.

True, hand-crafted assembly code will often beat what a compiler can do. But Java can use JNI to include native code, although with a certain overhead. But if the assembly code is much faster, or runs for a while, it may still be beneficial.

applications based on AI technologies such as chess, robotics etc. c/c++ is better choice.

If you had used real-time applications as an example, I'd have agreed (and even there Java is making strides), but AI is mainly based on algorithms. Those can be coded in Java at least as well as in C/C++.

this is the reason why 99% chess engines are written in C/C++

The most likely reason for this (apart from the one Gavin gave) is that the majority of desktop applications (which is were computer chess is mostly played) are written in C/C++; Java just isn't a contender on the desktop.


Ping & DNS - my free Android networking tools app
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
Originally posted by Rahul Bhattacharjee:
Hi vikas chess ,

Kindly check with the javaranch's naming policy.I am sure chess is not your last name.

In terms of performance Java has improved a lot from its earlier version.It's JIT takes care of converting heavily used byte codes into native.
I have not done any performance benchmarking on java's speed , but I am sure that if its not faster , then its not much slower also.


my last name is already taken by someone else

one of my friend code a chess engine in java and then apply the same logic in c. his c code was running 20 times faster than java one
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
Originally posted by Gavin Tranter:
You know, you can prove anything you wish with statistics.

I would say the reason 99% of chess engines are written in C/C++ is more to do with C/C++ having been around longer.


we cant prove everything with statistics. and when i am saying 99% then it really matters. all the strong engines such as crafty, fritz, deep junior etc. are written in c.

and java is also not a new language. so its a lame excuse that chess engines are written in c rather than java because its old. when so many games are developed in java. why not chess?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
Originally posted by vikas chess:
when so many games are developed in java. why not chess?

I don't think there are many commercial games written in Java. Chess is too hard to do it well on a not-for-profit basis. And since for various reasons there is no market for commercial Java games, nobody who could do the chess part, will do it in Java.

one of my friend code a chess engine in java and then apply the same logic in c. his c code was running 20 times faster than java one

With all due respect to your friend, that proves that he can write a C version that is 20 times as fast as the Java version he can write, and little else. Java and C are so different that trying to use the same design in both languages will lead to a decidedly suboptimal design for one of them.

my last name is already taken by someone else

So now that you've admitted that "chess" is not your last name, please chnage it to a valid one. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
Originally posted by Ulf Dittmer:

I don't think there are many commercial games written in Java. Chess is too hard to do it well on a not-for-profit basis. And since for various reasons there is no market for commercial Java games, nobody who could do the chess part, will do it in Java.


for your information, there are many commercial games developed in java especially j2me. none of the commercial chess engines are written in java.

With all due respect to your friend, that proves that he can write a C version that is 20 times as fast as the Java version he can write, and little else. Java and C are so different that trying to use the same design in both languages will lead to a decidedly suboptimal design for one of them.


speed depends upon the logic not design. and if a person is writing a chess engine in java. he must be having sound knowledge of java. why don't you write a chess engine and compare its speed with c code?


So now that you've admitted that "chess" is not your last name


its obvious chess can't be a last name. there is nothing to hide in it. and nor its a crime. i will change it later on. the new member may not be aware of all the rules. be on topic.
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
Originally posted by Ulf Dittmer:

True, hand-crafted assembly code will often beat what a compiler can do. But Java can use JNI to include native code, although with a certain overhead. But if the assembly code is much faster, or runs for a while, it may still be beneficial.


java can use JNI. but as you said with certain overhead and limitations. whereas in C there is no overhead. also in C one can embed assembly code inside the C code which is not possible in java. there are many low level tricks we can use in C/C++ to optimize speed (for e.g. using 4 bit flag to implement castling rules, or pawn promotion rules etc.). C is very near to system languages.

java is good for writing object-oriented web-based robust applications at the cost of speed/memory.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
Originally posted by vikas chess:
for your information, there are many commercial games developed in java especially j2me. none of the commercial chess engines are written in java.

True, for J2ME there are quite few games. I thought we were talking about desktop Java (I was, at least ). Are there any good chess implementations for mobile phones, whatever the language?

if a person is writing a chess engine in java. he must be having sound knowledge of java. why don't you write a chess engine and compare its speed with c code?

I couldn't write a decent chess program in any language. I could write a bad one in any number of languages, most of which I know very well. That doesn't prove that it's impossible to write a decent or fast one in these languages.

What's more, it's perfectly possible to write awful code in any language that still translates into a correctly running program. (Note that I'm not talking about your friend - we're having an abstract discussion here.)

The important point, though, is that the fact that one person wasn't able to do something does not prove it's impossible - it simply proves that this person couldn't do it. No generalization is logically possible.
On the other hand, if one person is able to something, that does indeed prove the general case - that it is possible.

its obvious chess can't be a last name. there is nothing to hide in it. and nor its a crime. i will change it later on. the new member may not be aware of all the rules. be on topic.

You may not have noticed that I'm one of the moderators of this site. Reminding someone of the rules we have is always "on topic". Thanks in advance.
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
Originally posted by Ulf Dittmer:

Are there any good chess implementations for mobile phones, whatever the language.


there are some chess engines for mobile phones also, written in brew(not sure). but there are some multiplayer mobile chess games available in the market developed in j2me. for networking java is excellent!


I couldn't write a decent chess program in any language. I could write a bad one in any number of languages, most of which I know very well. That doesn't prove that it's impossible to write a decent or fast one in these languages.


its going to an endless discussion. let me try to write a chess engine in java itself. it would take sometime as i am busy with my current job. i hope it runs as fast as it was running in my c++ code. because for 3 years i am working in java and i don't want to code in c/c++ now
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Originally posted by Ulf Dittmer:
True, hand-crafted assembly code will often beat what a compiler can do.


Feh. This really isn't true anymore, either, although there are just as many ASM-vs-C bigots as C-vs-Java bigots who won't surrender the notion. Ever since the Pentium Pro came out, and especially the Pentium II, it's pretty much impossible to beat a really good compiler most of the time (and by really good, I mean real commercial compilers like Portland Group's or Intel's, not gcc!) Ever since instruction pairing, pipelining, and speculative execution, second-guessing the compiler has become a fruitless exercise. Sure, you might save a few bits of storage using asm instead of C, but you're not really going to write faster code for anything nontrivial.

Now, if you really want to get all theoretical: I'm sure you know that FORTRAN has long been acknowledged to be faster than C because C has that whole nasty aliasing problem, right? C compilers are restricted in what optimizations they can do because any one block of memory can have many different pointers poking into it that the compiler might not even know about. FORTRAN is different; the compiler can always understand any aliasing, so that cache and the register file can be used more efficiently.

But as Ulf was implying, Java doesn't have the aliasing problem! HotSpot knows as much as a FORTRAN compiler about what's going on, meaning that Java can use some optimizations that C can't! As someone who writes fast AI algorithms for a living, I can assure you that the performance gap between what the best C and Java programmers produce has essentially disappeared.

Finally, please add a last name to your display name. If your real last name is already taken, then add a middle initial. Thanks.


[Jess in Action][AskingGoodQuestions]
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
Originally posted by Ernest Friedman-Hill:


Feh. This really isn't true anymore, either, although there are just as many ASM-vs-C bigots as C-vs-Java bigots who won't surrender the notion.


below is the code i used in my chess engine written in C, to find out the position of least significant bit that is set in a 64-bit variable bb:

int CChess::LSB(BitBoard &bb)
{
int Index;

__asm mov esi, bb // Get Address from bb

__asm mov ebx, [esi] // Load 1st 32Bit into EBX
__asm and ebx,ebx // Is EBX Zero? No Bit set here
__asm jz l2 // Jmp to the next test
__asm bsf eax, ebx // Get BitNumer (Bit Scan Forward)
__asm jmp found // and finish the routine
l2:
__asm mov ebx, [esi+4] // Load 2nd 32Bit into EBX
__asm and ebx,ebx // is this zero?
__asm jz l3 // Yes: Jump
__asm bsf eax, ebx // No: Search Bit and save the BitNr in EAX
__asm add eax,32 // Add to BitNr 32
__asm jmp found // Finish the routine
l3:
__asm mov eax,0xff // No Bit found - Index will be 0xff
found:
__asm mov Index,eax // Transfer the bitnr to Index

return Index;
}

above method is called very frequently inside the alpha-beta search. so its need to be very efficeint. how can we achieve the same in java in the most efficient way?

in other words, how can we implement BSF(Bit Scan Forward) assembly code in java in the most efficient way.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"vikas",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with invalid display names get deleted, often without warning

thanks,
Dave
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
how can we implement BSF(Bit Scan Forward) assembly code in java in the most efficient way

what happened? no answers??
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14345
    
  22

vikas sh,

Sorry to bother you again about your username! Your name is still not according to the naming policy.

Please change your name and choose a real-sounding second name instead of "sh".

Note, the naming policy does not require you to choose your real name. If you are not comfortable to use your real name here, that's no problem. But we do ask of you that you use a real-sounding, not obviously fictitious name, and not just initials like "sh".

Please carefully read the naming policy and choose a good display name.
[ July 08, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Vikas, it's the weekend, and not everyone is sitting around waiting to answer your posts.

Probably the best way to achieve that functionality in Java is with Long.numberOfTrailingZeros(). For a JDK earlier than JDK 5, you can just check out the source code from JDK 5 to see what they did. Other implementations are possible, which may be optimized according to the distribution of the input, checking the most common cases first. Tuning this way you may get something faster, but it will probably be close either way.

I imagine that this particular operation is probably faster in C than Java, if you can rely directly on an assembly language instruction that doesn't exist in JVM bytecode. However I suspect that the numberOfTrailingZeros() performance is not too many orders of magnitude behind. Performance gains in other areas could offset this. Moreover in a program designed for Java you might well set up your algorithms and data structures so that this particular operation is never required.

Certainly there are some specific things that are significantly faster in C than in Java, but there are many variables that go into overall performance, and I wouldn't be too quick to rule out the possibility of a strong, performant Java chess program. If nothing else, it makes a good challenge for people to see how well they can get Java to do in this arena.


"I'm not back." - Bill Harding, Twister
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
Originally posted by Jim Yingst:

Probably the best way to achieve that functionality in Java is with Long.numberOfTrailingZeros(). For a JDK earlier than JDK 5, you can just check out the source code from JDK 5 to see what they did.


thanks Jim. i go through the code of Long.numberOfTrailingZeros().

here it is:

public static int numberOfTrailingZeros(long i) {
// HD, Figure 5-14
int x, y;
if (i == 0) return 64;
int n = 63;
y = (int)i; if (y != 0) { n = n -32; x = y; } else x = (int)(i>>>32);
y = x <<16; if (y != 0) { n = n -16; x = y; }
y = x << 8; if (y != 0) { n = n - 8; x = y; }
y = x << 4; if (y != 0) { n = n - 4; x = y; }
y = x << 2; if (y != 0) { n = n - 2; x = y; }
return n - ((x << 1) >>> 31);
}

this code will be quiet slower than assembly code above. but i think this is the most efficient way we can implement Bit Scan Forward in java.

in java 1.5, there is a similar method named lowestOneBit, which is implemented very efficiently but return value rather than index of the lowest bit.
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Stats can prove anything and everything,
"99% of chess engines are written in C/C++"
.
What you chose to attach to the meaning of that 99% is upto you, you chose to take it to mean that Java is bad for the job (perhaps it is) I chose to take it to mean that due to the relative ages of the two technologies that one of the technologies has had time to build up a large base of Chess engines.

Just two ways of looking at the same "fact", heres another two: 99% of chess engines are written in a language that is at least 20-30years old. (not sure when C++ showed up).
It could be that 1% of none C/C++ chess engines are the best they possible can be, so no further development is need on them, and every body has chosen them as some defacto standard for that language. (Unlikely but certainly one way of looking at the "facts")

I would chose Java over C/C++ to write any game (or any application), because I am comfortable with the language, I am limited in my choice by which language I think I can accomplish the task in.
I also believe, and could be wrong, that you can design your game much better in an OO language.

If i understood the rules of chess better, and was a better developer then I am I would give a chess engine in Java a go, perhaps you should, without any thought to your Java/C++ version, clean sheet of paper.
None of the "if i was in C i could do this...." be the JVM

I have been reading the Java Puzzles book (sorry I dont know the writters or any other details) and they suggest that Java's memory allocation is faster then direct manipulation of the memory space (as in C), the reason being (apprently) that you really dont have that kind of direct access to memory anymore, the OS is always between you and memory, taking your memory instructions and remapping them, thus in C you are adding over head by having direct manipulation.
Dont know if its true or not, it sounds good, and about right.

Anyway just my �2

G
[ July 09, 2007: Message edited by: Gavin Tranter ]
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
Originally posted by Gavin Tranter:
Just two ways of looking at the same "fact", heres another two: 99% of chess engines are written in a language that is at least 20-30years old. (not sure when C++ showed up).
It could be that 1% of none C/C++ chess engines are the best they possible can be, so no further development is need on them, and every body has chosen them as some defacto standard for that language. (Unlikely but certainly one way of looking at the "facts")

these are your assumptions not facts. daily hundreds of chess engines are developed, and most of them developed in c/c++. there are professional programmers whose livelihood is based on chess engines. none of them choose java. why? take example of fritz, deep junior, Rybka, Shredder, Zappa etc[ July 09, 2007: Message edited by: Gavin Tranter ][/QB]


I would chose Java over C/C++ to write any game (or any application), because I am comfortable with the language, I am limited in my choice by which language I think I can accomplish the task in.
I also believe, and could be wrong, that you can design your game much better in an OO language.

for non-AI games or not highly computing oriented games, java is OK.

If i understood the rules of chess better, and was a better developer then I am I would give a chess engine in Java a go, perhaps you should, without any thought to your Java/C++ version, clean sheet of paper.
None of the "if i was in C i could do this...." be the JVM

obviously anyone can develop a chess engine in java. here question is as efficient as in C/C++.

I have been reading the Java Puzzles book (sorry I dont know the writters or any other details) and they suggest that Java's memory allocation is faster then direct manipulation of the memory space (as in C), the reason being (apprently) that you really dont have that kind of direct access to memory anymore, the OS is always between you and memory, taking your memory instructions and remapping them, thus in C you are adding over head by having direct manipulation.
Dont know if its true or not, it sounds good, and about right.

thanks for information.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I was thinking about the BSF problem some more, and came up with a perverse-looking but very fast solution that tends to minimize the number of java bytecodes that would need to get executed on each call. Here's one version, checking 4 bits at a time:

And here's another version that checks 8 bits at a time:

The second is faster but much longer; in general the difference in performance will be small unless it's very common to have inputs with more than 4 trailing zeros (i.e., does this occur more than half the time?). Assuming that's unusual, most inputs will be resolved within the very first switch statement. In the event that inputs with a lot of trailing zeros are extremely common, you could theoretically go as high as checking 11 bits at a time, before the size of the code exceeds the amount allowed in a single method (64kB). (The bulk of the method would be a series of tableswitch commands where each jump table uses 4 bytes per case in the switch statement - at 11 bits each tableswitch has 2048 cases, and 6 tableswitches will be required.) I'm deliberately avoiding calling other methods within the main method, just because I'm really micro-optimizing. Perverse, I know, but if this method is really dominating overall performance and we're down to minimizing the bytecodes as you did in C, it would be worth it. Um, probably. But I really think checking 4-8 bits at a time is quite enough.

Now it's true that the perverse length of these methods isn't actually a great endorsement for using Java to program chess. But this is just one performance-dominating method which happened to rely on an assembly language instruction that the JVM does not duplicate - how many of those cases can there be? Most other assembly language instructions have much closer analogs in the JVM. And it's far from certain that a good Java-based design would even end up relying on needing to count trailing zero bits in a long, though I really don't know enough about how and why it's being used here.

Anayway, it was an interesting challenge, at least.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
That looks heavy, for my chess program I do something like this to find the bits:

First I create a MAGIC array that can be used with Debrujn sequences:


Then you need a special constant

Then once you have the target squares as a long (MOVES), you can use
MOVES & -MOVES to get least bit, and MOVES & (MOVES-1) to remove the least bit.
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
thanks a ton! colin. this is the best and fastest approach.

i too had figured out (MOVES & -MOVES) logic but was not able to find an efficient way to convert it into index. i was thinking of using arrays too but nothing struck to my mind.

you are simply genius!

your code is giving the expected result. but can you please explain me the logic behind it.

following logics i understood:

1. the constant value of deBrujn is the de Bruijn sequence of order 6.

2. the right shift 58 is used to get the value of first 6 MSB bit, which represents index value of MAGIC array from 0 to 63.

3. (MOVES & -MOVES) is returning the value of lowest bit.

But i am unable to understand the following logics:

1. how values of MAGIC array is determined?

2. what is the logic behind multiplying deBrujn constant with (MOVES & -MOVES)?
[ July 11, 2007: Message edited by: vikas chess ]
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Jim, that is evil code I like it
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I try.
[ July 10, 2007: Message edited by: Jim Yingst ]
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
i understood the complete logic now!

(deBrujn*(MOVES & -MOVES))>>>58) returns 64 different values ranging from 0 to 63 depends upon the lowest bit set in MOVES variable. the value will be unique for each lowest bit (this is the importance of deBrujn constant here!).

hence, we need to find out all these unique values and map it into an array (MAGIC array).

so, i wrote a code for this, as follows



in the above code, i pass 64 different values in the form of x variable. for each value of x, different lowest bit is set from LSB to MSB. now, we can create an array, for instance, MAGIC array which will map the corresponding bit index to the result.

i am very happy that i myself figure out the complete logic.

anyway, i am very thankful to colin for providing this logic.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Yes, good stuff, I think you understand it quite well.

If you take that big magic number (64 bits)
and write out all the bits...
010110 ... 1110 or whatever it is, then as you scan through it, each 6 bits is different.

Since you have DEBRUJN * LEAST_BIT,
remember LEAST_BIT is always just a power of 2, so effectively your just left shifting DEBRUJN when you multiply, giving you a new 64 bit number.

The top 6 bits will always be unique in this number, and thats when you use the array.

Initially I was taking logs, eg to get the value 10 from 1024, but when I swapped to this method, the program literally doubled in speed, showing just how costly the fancy math methods are.

Glad to be of some help though, maybe you can help me too with bits on my engine.

Add me to messenger if you want someone to chat chess engines with
(yahoo)cms271828@yahoo.co.uk,
(msn)colin.shuker@tiscali.co.uk

Thanks.
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
Originally posted by colin shuker:
Yes, good stuff, I think you understand it quite well.
Glad to be of some help though, maybe you can help me too with bits on my engine.

Add me to messenger if you want someone to chat chess engines with
(yahoo)cms271828@yahoo.co.uk,
(msn)colin.shuker@tiscali.co.uk

Thanks.


yeah colin, i understood it very well. i had writtend chess engine in vc++ four years back. now i am writing it in java. we shall share our knowledge here. i am sending add request to you.

my id at yahoo is vikas_chess@yahoo
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Chess Game I made by my self