[llvm-commits] CVS: llvm-test/MultiSource/Applications/hexxagon/COPYING LICENSE.TXT Makefile bitboard64.cpp bitboard64.h hexxagon.cpp hexxagonboard.cpp hexxagonboard.h hexxagongame.cpp hexxagongame.h hexxagonmove.cpp hexxagonmove.h input libhexx.h

John Criswell criswell at cs.uiuc.edu
Fri Sep 10 07:26:06 PDT 2004



Changes in directory llvm-test/MultiSource/Applications/hexxagon:

COPYING added (r1.1)
LICENSE.TXT added (r1.1)
Makefile added (r1.1)
bitboard64.cpp added (r1.1)
bitboard64.h added (r1.1)
hexxagon.cpp added (r1.1)
hexxagonboard.cpp added (r1.1)
hexxagonboard.h added (r1.1)
hexxagongame.cpp added (r1.1)
hexxagongame.h added (r1.1)
hexxagonmove.cpp added (r1.1)
hexxagonmove.h added (r1.1)
input added (r1.1)
libhexx.h added (r1.1)
---
Log message:

Misha informed me that Oscar's missed my commits to the LLVM tree, so here
goes:
Adding the hexxagon program to the test suite.  Hexxagon can play a board
game against itself (I believe the game is Ataxx) and takes about 15-20
seconds to run on Choi.  Hopefully it's run time and algorithms will be
ideal for testing optimizations (maybe even Pool Allocator someday).


---
Diffs of the changes:  (+2236 -0)

Index: llvm-test/MultiSource/Applications/hexxagon/COPYING
diff -c /dev/null llvm-test/MultiSource/Applications/hexxagon/COPYING:1.1
*** /dev/null	Fri Sep 10 09:26:03 2004
--- llvm-test/MultiSource/Applications/hexxagon/COPYING	Fri Sep 10 09:25:52 2004
***************
*** 0 ****
--- 1,339 ----
+ 		    GNU GENERAL PUBLIC LICENSE
+ 		       Version 2, June 1991
+ 
+  Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+                           675 Mass Ave, Cambridge, MA 02139, USA
+  Everyone is permitted to copy and distribute verbatim copies
+  of this license document, but changing it is not allowed.
+ 
+ 			    Preamble
+ 
+   The licenses for most software are designed to take away your
+ freedom to share and change it.  By contrast, the GNU General Public
+ License is intended to guarantee your freedom to share and change free
+ software--to make sure the software is free for all its users.  This
+ General Public License applies to most of the Free Software
+ Foundation's software and to any other program whose authors commit to
+ using it.  (Some other Free Software Foundation software is covered by
+ the GNU Library General Public License instead.)  You can apply it to
+ your programs, too.
+ 
+   When we speak of free software, we are referring to freedom, not
+ price.  Our General Public Licenses are designed to make sure that you
+ have the freedom to distribute copies of free software (and charge for
+ this service if you wish), that you receive source code or can get it
+ if you want it, that you can change the software or use pieces of it
+ in new free programs; and that you know you can do these things.
+ 
+   To protect your rights, we need to make restrictions that forbid
+ anyone to deny you these rights or to ask you to surrender the rights.
+ These restrictions translate to certain responsibilities for you if you
+ distribute copies of the software, or if you modify it.
+ 
+   For example, if you distribute copies of such a program, whether
+ gratis or for a fee, you must give the recipients all the rights that
+ you have.  You must make sure that they, too, receive or can get the
+ source code.  And you must show them these terms so they know their
+ rights.
+ 
+   We protect your rights with two steps: (1) copyright the software, and
+ (2) offer you this license which gives you legal permission to copy,
+ distribute and/or modify the software.
+ 
+   Also, for each author's protection and ours, we want to make certain
+ that everyone understands that there is no warranty for this free
+ software.  If the software is modified by someone else and passed on, we
+ want its recipients to know that what they have is not the original, so
+ that any problems introduced by others will not reflect on the original
+ authors' reputations.
+ 
+   Finally, any free program is threatened constantly by software
+ patents.  We wish to avoid the danger that redistributors of a free
+ program will individually obtain patent licenses, in effect making the
+ program proprietary.  To prevent this, we have made it clear that any
+ patent must be licensed for everyone's free use or not licensed at all.
+ 
+   The precise terms and conditions for copying, distribution and
+ modification follow.
+ 
+ 		    GNU GENERAL PUBLIC LICENSE
+    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+ 
+   0. This License applies to any program or other work which contains
+ a notice placed by the copyright holder saying it may be distributed
+ under the terms of this General Public License.  The "Program", below,
+ refers to any such program or work, and a "work based on the Program"
+ means either the Program or any derivative work under copyright law:
+ that is to say, a work containing the Program or a portion of it,
+ either verbatim or with modifications and/or translated into another
+ language.  (Hereinafter, translation is included without limitation in
+ the term "modification".)  Each licensee is addressed as "you".
+ 
+ Activities other than copying, distribution and modification are not
+ covered by this License; they are outside its scope.  The act of
+ running the Program is not restricted, and the output from the Program
+ is covered only if its contents constitute a work based on the
+ Program (independent of having been made by running the Program).
+ Whether that is true depends on what the Program does.
+ 
+   1. You may copy and distribute verbatim copies of the Program's
+ source code as you receive it, in any medium, provided that you
+ conspicuously and appropriately publish on each copy an appropriate
+ copyright notice and disclaimer of warranty; keep intact all the
+ notices that refer to this License and to the absence of any warranty;
+ and give any other recipients of the Program a copy of this License
+ along with the Program.
+ 
+ You may charge a fee for the physical act of transferring a copy, and
+ you may at your option offer warranty protection in exchange for a fee.
+ 
+   2. You may modify your copy or copies of the Program or any portion
+ of it, thus forming a work based on the Program, and copy and
+ distribute such modifications or work under the terms of Section 1
+ above, provided that you also meet all of these conditions:
+ 
+     a) You must cause the modified files to carry prominent notices
+     stating that you changed the files and the date of any change.
+ 
+     b) You must cause any work that you distribute or publish, that in
+     whole or in part contains or is derived from the Program or any
+     part thereof, to be licensed as a whole at no charge to all third
+     parties under the terms of this License.
+ 
+     c) If the modified program normally reads commands interactively
+     when run, you must cause it, when started running for such
+     interactive use in the most ordinary way, to print or display an
+     announcement including an appropriate copyright notice and a
+     notice that there is no warranty (or else, saying that you provide
+     a warranty) and that users may redistribute the program under
+     these conditions, and telling the user how to view a copy of this
+     License.  (Exception: if the Program itself is interactive but
+     does not normally print such an announcement, your work based on
+     the Program is not required to print an announcement.)
+ 
+ These requirements apply to the modified work as a whole.  If
+ identifiable sections of that work are not derived from the Program,
+ and can be reasonably considered independent and separate works in
+ themselves, then this License, and its terms, do not apply to those
+ sections when you distribute them as separate works.  But when you
+ distribute the same sections as part of a whole which is a work based
+ on the Program, the distribution of the whole must be on the terms of
+ this License, whose permissions for other licensees extend to the
+ entire whole, and thus to each and every part regardless of who wrote it.
+ 
+ Thus, it is not the intent of this section to claim rights or contest
+ your rights to work written entirely by you; rather, the intent is to
+ exercise the right to control the distribution of derivative or
+ collective works based on the Program.
+ 
+ In addition, mere aggregation of another work not based on the Program
+ with the Program (or with a work based on the Program) on a volume of
+ a storage or distribution medium does not bring the other work under
+ the scope of this License.
+ 
+   3. You may copy and distribute the Program (or a work based on it,
+ under Section 2) in object code or executable form under the terms of
+ Sections 1 and 2 above provided that you also do one of the following:
+ 
+     a) Accompany it with the complete corresponding machine-readable
+     source code, which must be distributed under the terms of Sections
+     1 and 2 above on a medium customarily used for software interchange; or,
+ 
+     b) Accompany it with a written offer, valid for at least three
+     years, to give any third party, for a charge no more than your
+     cost of physically performing source distribution, a complete
+     machine-readable copy of the corresponding source code, to be
+     distributed under the terms of Sections 1 and 2 above on a medium
+     customarily used for software interchange; or,
+ 
+     c) Accompany it with the information you received as to the offer
+     to distribute corresponding source code.  (This alternative is
+     allowed only for noncommercial distribution and only if you
+     received the program in object code or executable form with such
+     an offer, in accord with Subsection b above.)
+ 
+ The source code for a work means the preferred form of the work for
+ making modifications to it.  For an executable work, complete source
+ code means all the source code for all modules it contains, plus any
+ associated interface definition files, plus the scripts used to
+ control compilation and installation of the executable.  However, as a
+ special exception, the source code distributed need not include
+ anything that is normally distributed (in either source or binary
+ form) with the major components (compiler, kernel, and so on) of the
+ operating system on which the executable runs, unless that component
+ itself accompanies the executable.
+ 
+ If distribution of executable or object code is made by offering
+ access to copy from a designated place, then offering equivalent
+ access to copy the source code from the same place counts as
+ distribution of the source code, even though third parties are not
+ compelled to copy the source along with the object code.
+ 
+   4. You may not copy, modify, sublicense, or distribute the Program
+ except as expressly provided under this License.  Any attempt
+ otherwise to copy, modify, sublicense or distribute the Program is
+ void, and will automatically terminate your rights under this License.
+ However, parties who have received copies, or rights, from you under
+ this License will not have their licenses terminated so long as such
+ parties remain in full compliance.
+ 
+   5. You are not required to accept this License, since you have not
+ signed it.  However, nothing else grants you permission to modify or
+ distribute the Program or its derivative works.  These actions are
+ prohibited by law if you do not accept this License.  Therefore, by
+ modifying or distributing the Program (or any work based on the
+ Program), you indicate your acceptance of this License to do so, and
+ all its terms and conditions for copying, distributing or modifying
+ the Program or works based on it.
+ 
+   6. Each time you redistribute the Program (or any work based on the
+ Program), the recipient automatically receives a license from the
+ original licensor to copy, distribute or modify the Program subject to
+ these terms and conditions.  You may not impose any further
+ restrictions on the recipients' exercise of the rights granted herein.
+ You are not responsible for enforcing compliance by third parties to
+ this License.
+ 
+   7. If, as a consequence of a court judgment or allegation of patent
+ infringement or for any other reason (not limited to patent issues),
+ conditions are imposed on you (whether by court order, agreement or
+ otherwise) that contradict the conditions of this License, they do not
+ excuse you from the conditions of this License.  If you cannot
+ distribute so as to satisfy simultaneously your obligations under this
+ License and any other pertinent obligations, then as a consequence you
+ may not distribute the Program at all.  For example, if a patent
+ license would not permit royalty-free redistribution of the Program by
+ all those who receive copies directly or indirectly through you, then
+ the only way you could satisfy both it and this License would be to
+ refrain entirely from distribution of the Program.
+ 
+ If any portion of this section is held invalid or unenforceable under
+ any particular circumstance, the balance of the section is intended to
+ apply and the section as a whole is intended to apply in other
+ circumstances.
+ 
+ It is not the purpose of this section to induce you to infringe any
+ patents or other property right claims or to contest validity of any
+ such claims; this section has the sole purpose of protecting the
+ integrity of the free software distribution system, which is
+ implemented by public license practices.  Many people have made
+ generous contributions to the wide range of software distributed
+ through that system in reliance on consistent application of that
+ system; it is up to the author/donor to decide if he or she is willing
+ to distribute software through any other system and a licensee cannot
+ impose that choice.
+ 
+ This section is intended to make thoroughly clear what is believed to
+ be a consequence of the rest of this License.
+ 
+   8. If the distribution and/or use of the Program is restricted in
+ certain countries either by patents or by copyrighted interfaces, the
+ original copyright holder who places the Program under this License
+ may add an explicit geographical distribution limitation excluding
+ those countries, so that distribution is permitted only in or among
+ countries not thus excluded.  In such case, this License incorporates
+ the limitation as if written in the body of this License.
+ 
+   9. The Free Software Foundation may publish revised and/or new versions
+ of the General Public License from time to time.  Such new versions will
+ be similar in spirit to the present version, but may differ in detail to
+ address new problems or concerns.
+ 
+ Each version is given a distinguishing version number.  If the Program
+ specifies a version number of this License which applies to it and "any
+ later version", you have the option of following the terms and conditions
+ either of that version or of any later version published by the Free
+ Software Foundation.  If the Program does not specify a version number of
+ this License, you may choose any version ever published by the Free Software
+ Foundation.
+ 
+   10. If you wish to incorporate parts of the Program into other free
+ programs whose distribution conditions are different, write to the author
+ to ask for permission.  For software which is copyrighted by the Free
+ Software Foundation, write to the Free Software Foundation; we sometimes
+ make exceptions for this.  Our decision will be guided by the two goals
+ of preserving the free status of all derivatives of our free software and
+ of promoting the sharing and reuse of software generally.
+ 
+ 			    NO WARRANTY
+ 
+   11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+ REPAIR OR CORRECTION.
+ 
+   12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGES.
+ 
+ 		     END OF TERMS AND CONDITIONS
+ 
+ 	Appendix: How to Apply These Terms to Your New Programs
+ 
+   If you develop a new program, and you want it to be of the greatest
+ possible use to the public, the best way to achieve this is to make it
+ free software which everyone can redistribute and change under these terms.
+ 
+   To do so, attach the following notices to the program.  It is safest
+ to attach them to the start of each source file to most effectively
+ convey the exclusion of warranty; and each file should have at least
+ the "copyright" line and a pointer to where the full notice is found.
+ 
+     <one line to give the program's name and a brief idea of what it does.>
+     Copyright (C) 19yy  <name of author>
+ 
+     This program is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published by
+     the Free Software Foundation; either version 2 of the License, or
+     (at your option) any later version.
+ 
+     This program is distributed in the hope that it will be useful,
+     but WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+     GNU General Public License for more details.
+ 
+     You should have received a copy of the GNU General Public License
+     along with this program; if not, write to the Free Software
+     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ 
+ Also add information on how to contact you by electronic and paper mail.
+ 
+ If the program is interactive, make it output a short notice like this
+ when it starts in an interactive mode:
+ 
+     Gnomovision version 69, Copyright (C) 19yy name of author
+     Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+     This is free software, and you are welcome to redistribute it
+     under certain conditions; type `show c' for details.
+ 
+ The hypothetical commands `show w' and `show c' should show the appropriate
+ parts of the General Public License.  Of course, the commands you use may
+ be called something other than `show w' and `show c'; they could even be
+ mouse-clicks or menu items--whatever suits your program.
+ 
+ You should also get your employer (if you work as a programmer) or your
+ school, if any, to sign a "copyright disclaimer" for the program, if
+ necessary.  Here is a sample; alter the names:
+ 
+   Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+   `Gnomovision' (which makes passes at compilers) written by James Hacker.
+ 
+   <signature of Ty Coon>, 1 April 1989
+   Ty Coon, President of Vice
+ 
+ This General Public License does not permit incorporating your program into
+ proprietary programs.  If your program is a subroutine library, you may
+ consider it more useful to permit linking proprietary applications with the
+ library.  If this is what you want to do, use the GNU Library General
+ Public License instead of this License.


Index: llvm-test/MultiSource/Applications/hexxagon/LICENSE.TXT
diff -c /dev/null llvm-test/MultiSource/Applications/hexxagon/LICENSE.TXT:1.1
*** /dev/null	Fri Sep 10 09:26:05 2004
--- llvm-test/MultiSource/Applications/hexxagon/LICENSE.TXT	Fri Sep 10 09:25:52 2004
***************
*** 0 ****
--- 1,26 ----
+ Hexxagon
+ ------------------------------------------------------------------------------
+ The Hexxagon code has the following additional copyright and restrictions:
+ 
+ Copyright (C) 2001 Erik Jonsson.
+ 
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+ 
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ 
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ 
+ Please see the file COPYING for more information.
+ 
+ This tree is only a subset of the original Hexxagon source.  Namely, the X11
+ code has been removed, and the source from libhexx has been integrated directly
+ into the program.
+ 


Index: llvm-test/MultiSource/Applications/hexxagon/Makefile
diff -c /dev/null llvm-test/MultiSource/Applications/hexxagon/Makefile:1.1
*** /dev/null	Fri Sep 10 09:26:05 2004
--- llvm-test/MultiSource/Applications/hexxagon/Makefile	Fri Sep 10 09:25:52 2004
***************
*** 0 ****
--- 1,7 ----
+ LEVEL = ../../..
+ PROG = hexxagon
+ REQUIRES_EH_SUPPORT = 1
+ LDFLAGS += -lstdc++ -lreadline -ltermcap
+ LIBS += -lstdc++ -lreadline -ltermcap
+ STDIN_FILENAME=$(BUILD_SRC_DIR)/input
+ include ../../Makefile.multisrc


Index: llvm-test/MultiSource/Applications/hexxagon/bitboard64.cpp
diff -c /dev/null llvm-test/MultiSource/Applications/hexxagon/bitboard64.cpp:1.1
*** /dev/null	Fri Sep 10 09:26:05 2004
--- llvm-test/MultiSource/Applications/hexxagon/bitboard64.cpp	Fri Sep 10 09:25:52 2004
***************
*** 0 ****
--- 1,219 ----
+ /*
+  * Hexxagon board game.
+  * Copyright (C) 2001 Erik Jonsson.
+  * 
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * 
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+  * 
+  * Email erik at nesqi.homeip.net
+  * 
+  */
+ 
+ #include "bitboard64.h"
+ #include <stdio.h>
+ #include <iostream>
+ #include <netinet/in.h>
+ 
+ using namespace std;
+ 
+ BitBoard64 BitBoard64::operator~(void)
+ {
+ 	BitBoard64 ret(~lowbits, ~highbits);
+ 	return ret;
+ }
+ 
+ BitBoard64 BitBoard64::operator&(const BitBoard64 &right)
+ {
+ 	BitBoard64 ret(lowbits & right.lowbits, highbits & right.highbits);
+ 	return ret;
+ }
+ 
+ BitBoard64 BitBoard64::operator|(const BitBoard64 &right)
+ {
+ 	BitBoard64 ret(lowbits | right.lowbits, highbits | right.highbits);
+ 	return ret;
+ }
+ 
+ BitBoard64 BitBoard64::operator=(const BitBoard64 &right)
+ {
+ 	lowbits = right.lowbits;
+ 	highbits = right.highbits;
+ 	return *this;
+ }
+ 
+ BitBoard64 BitBoard64::operator^(const BitBoard64 &right)
+ {
+ 	BitBoard64 ret(lowbits ^ right.lowbits, highbits ^ right.highbits);
+ 	return ret;
+ }
+ 
+ BitBoard64::operator bool()
+ {
+ 	return (bool)(lowbits || highbits);
+ }
+ 
+ void BitBoard64::setBit(int bit)
+ {
+ 	if((bit < 0) || (bit > 63))
+ 		return;
+ 
+ 	if(bit < 32)
+ 		lowbits |= (1 << bit);
+ 	else
+ 		highbits |= (1 << (bit-32));
+ }
+ 
+ void BitBoard64::unSetBit(int bit)
+ {
+ 	if((bit < 0) || (bit > 63))
+ 		return;
+ 
+ 	if(bit < 32)
+ 		lowbits &= ~(1 << bit);
+ 	else
+ 		highbits &= ~(1 << (bit-32));
+ }
+ 
+ int BitBoard64::getBit(int bit)
+ {
+ 	if((bit < 0) || (bit > 63))
+ 		return -1;
+ 
+ 	if(bit < 32)
+ 		return lowbits & (1 << bit);
+ 	else
+ 		return highbits & (1 << (bit-32));
+ }
+ 
+ int BitBoard64::readFromFile(FILE *file)
+ {
+ 	 lowbits = 0;
+ 	 highbits = 0;
+ 
+ 	 /* Just to get the same byte order. 
+ 		Could not use htonl; long int could be different sizes. */
+ 	 for(int i = 0; i < 4; i++)
+ 	 {
+ 		 uint8_t byte = 0;
+ 		 
+ 		 if(fread(&byte, 1, 1, file) != 1) 
+ 			 return -1;
+ 
+ 		 lowbits |=  byte << (i * 8);
+ 	 }
+ 
+ 	 for(int i = 0; i < 4; i++)
+ 	 {
+ 		 uint8_t byte = 0;
+ 		 
+ 		 if(fread(&byte, 1, 1, file) != 1) 
+ 			 return -1;
+ 
+ 		 highbits |=  byte << (i * 8);
+ 	 }
+ 
+ 	 return 0;
+ }
+ 
+ int BitBoard64::writeToFile(FILE *file)
+ {
+ 	/* Just to get the same byte order. */
+ 	for(int i = 0; i < 4; i++)
+ 	{
+ 		uint8_t byte = 0;
+ 		
+ 		byte = (lowbits >> (i * 8)) & 0xFF;
+ 	
+ 		if(fwrite(&byte, 1, 1, file) != 1) 
+ 			return -1;
+ 
+ 	}
+ 
+ 	for(int i = 0; i < 4; i++)
+ 	{
+ 		uint8_t byte = 0;
+ 		
+ 		byte = (highbits >> (i * 8)) & 0xFF;
+ 	
+ 		if(fwrite(&byte, 1, 1, file) != 1) 
+ 			return -1;
+ 
+ 	}
+ 	
+ 	return 0;
+ }
+ 
+ 
+ /*********************/
+ /* Debug struff      */
+ int getBFP(int x, int y)
+ {
+ 	int no;
+ 
+ 	if(x > 0 && x < 10 && y > 0 && y < 10)
+ 	{
+ 		if(y < 5)
+ 			if(x > (9 - (5 - y)))
+ 				return -1;
+ 
+ 		if(y > 5)
+ 			if(x <= (y - 5))
+ 				return -1;
+ 	  
+ 		no = x+y*9 - 10;
+ 	  
+ 		if(y > 1) no -= 4;
+ 		if(y > 2) no -= 3;
+ 		if(y > 3) no -= 2;
+ 		if(y > 4) no -= 1;
+ 		if(y > 5) no -= 1;
+ 		if(y > 6) no -= 2;
+ 		if(y > 7) no -= 3;
+ 		if(y > 8) no -= 4;
+ 	  
+ 		return no;
+ 	}
+ 
+ 	return -1;
+ }
+ 
+ void BitBoard64::print()
+ {
+ 	int x, y, no, off;
+ 
+ 	for(y = 1; y < 10; y++)
+ 	{
+ 		if(y < 5)
+ 		{
+ 			for(off = 0; off < (5 - y); off++)
+ 				cout << " ";
+ 		}
+ 		for(x = 1; x < 10; x++)
+ 		{
+ 			if((no = getBFP(x, y)) == -1)
+ 				cout << " ";
+ 			else
+ 			{
+ 				if(getBit(no))
+ 					cout << "x ";
+ 				else
+ 					cout << ". ";
+ 			}
+ 		}
+ 		cout << "\n";
+ 	}
+ }
+ 
+ 
+ 


Index: llvm-test/MultiSource/Applications/hexxagon/bitboard64.h
diff -c /dev/null llvm-test/MultiSource/Applications/hexxagon/bitboard64.h:1.1
*** /dev/null	Fri Sep 10 09:26:05 2004
--- llvm-test/MultiSource/Applications/hexxagon/bitboard64.h	Fri Sep 10 09:25:52 2004
***************
*** 0 ****
--- 1,57 ----
+ /*
+  * Hexxagon board game.
+  * Copyright (C) 2001 Erik Jonsson.
+  * 
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * 
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+  * 
+  * Email erik at nesqi.homeip.net
+  * 
+  */
+ 
+ #ifndef _BITBOARD64_H
+ #define _BITBOARD64_H
+ 
+ #include <netinet/in.h>
+ #include <stdio.h>
+ 
+ class BitBoard64
+ {
+  public:
+ 	BitBoard64(void) {};
+ 	BitBoard64(uint32_t l, uint32_t h) {lowbits = l, highbits = h;};
+ 
+ 	void setBit(int bit);
+ 	void unSetBit(int bit);
+ 	int  getBit(int bit);
+ 
+ 	BitBoard64 operator&(const BitBoard64 &right);
+ 	BitBoard64 operator|(const BitBoard64 &right);
+ 	BitBoard64 operator^(const BitBoard64 &right);
+ 	BitBoard64 operator=(const BitBoard64 &right);
+ 	BitBoard64 operator~(void);
+ 
+ 	BitBoard64::operator bool();
+ 
+ 	void print(void);
+ 
+ 	int readFromFile(FILE *file);
+ 	int writeToFile(FILE *file);
+ 
+  private:
+ 	
+ 	uint32_t lowbits, highbits;
+ };
+ 
+ #endif


Index: llvm-test/MultiSource/Applications/hexxagon/hexxagon.cpp
diff -c /dev/null llvm-test/MultiSource/Applications/hexxagon/hexxagon.cpp:1.1
*** /dev/null	Fri Sep 10 09:26:05 2004
--- llvm-test/MultiSource/Applications/hexxagon/hexxagon.cpp	Fri Sep 10 09:25:52 2004
***************
*** 0 ****
--- 1,436 ----
+ /*
+  * Hexxagon board game.
+  * Copyright (C) 2001 Erik Jonsson.
+  * 
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * 
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+  * 
+  * Email erik at nesqi.homeip.net
+  * 
+  */
+ 
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <readline/readline.h>
+ #include <readline/history.h>
+ #include <ctype.h>
+ #include <string.h>
+ 
+ #include <libhexx.h>
+ 
+ void stripFromDblSpace(char *cpfrom)
+ {
+ 	char *cpto = cpfrom;
+ 	int space = 1;
+ 	
+ 	while(*cpfrom)
+ 	{
+ 		if(!(space && (*cpfrom == ' ' || *cpfrom == '\t')))
+ 		{
+ 			*cpto = *cpfrom;
+ 			cpto++;
+ 		}
+ 		
+ 		if(*cpfrom == ' ' || *cpfrom == '\t')
+ 			space = 1;
+ 		else 
+ 			space = 0;
+ 		
+ 		cpfrom++;
+ 	}
+ 	
+ 	*cpto = 0;
+ }
+ 
+ void printCopy()
+ {
+ 	printf("\n");
+ 	printf("Hexxagon board game.\n");
+ 	printf("Copyright (C) 2001 Erik Jonsson.\n\n");
+ 	
+ 	printf("The pieces was drawn by Stefan Påhlson.\n\n");
+ 
+ 	printf("This program is free software; you can redistribute it and/or\n");
+ 	printf("modify it under the terms of the GNU General Public License\n");
+ 	printf("as published by the Free Software Foundation; either version 2\n");
+ 	printf("of the License, or (at your option) any later version.\n\n");
+ 	
+ 	printf("This program is distributed in the hope that it will be useful,\n");
+ 	printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
+ 	printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");
+ 	printf("GNU General Public License for more details.\n\n");
+ 	
+ 	printf("You should have received a copy of the GNU General Public License\n");
+ 	printf("along with this program; if not, write to the Free Software\n");
+ 	printf("Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n\n");
+ 	
+ 	printf("Email erik at nesqi.homeip.net\n\n");
+ };
+ 
+ void printHelp()
+ {
+ 	printf("        __                              \n");
+ 	printf("     __/  \\__                          \n");
+ 	printf("  __/  \\__/  \\__      Hexxagon v0.3.1 \n");
+ 	printf(" /  \\__/  \\__/  \\     Copyright 2001 \n");
+ 	printf(" \\__/  \\__/  \\__/     Erik Jonsson   \n");
+ 	printf(" /  \\__/  \\__/  \\                    \n");
+ 	printf(" \\__/  \\__/  \\__/                    \n");
+ 	printf("    \\__/  \\__/                        \n");
+ 	printf("       \\__/                            \n\n");
+ 	printf(" erik at nesqi.homeip.net\n"); 
+ 	printf(" http://nesqi.homeip.net/hexxagon\n");
+ 	printf("\n");
+ 	printf(" Common commands:\n");
+ 	printf("   quit                  : Quit the program.\n");
+ 	printf("   help                  : Print this help.\n");
+ 	printf("   copyright             : Prints copyright information.\n\n");
+ 	printf(" Play related commands:\n");
+ 	printf("   jump  [FROM][TO]      : Jump from eg. A4 to B4.\n");
+ 	printf("   j     [FROM][TO]      : Same as jump.\n");
+ 	printf("   clone [TO]            : Clone to a position.\n");
+ 	printf("   c     [TO]            : Same as clone.\n");
+ 	printf("   hint                  : Let the computer move for you.\n");
+ 	printf("   board                 : Display the current playboard.\n");
+ 	printf("   undo                  : Go gack one half move. (Undo)\n");
+ 	printf("   redo                  : Goto the next half move. (If you have used \"undo\".)\n\n");
+ 	printf(" Game related commands:\n");
+ 	printf("   time [seconds]        : Max time for the computer to think.\n");
+ 	printf("   level [level]         : Max search depth for the computer the use.\n");
+ 	printf("   load [filename]       : Load a game from a save-file.\n");
+ 	printf("   save [filename]       : Save a game (with history) to a file.\n");
+ 	printf("   newgame [CC/HC/CH/HH] : Start a new game:\n");
+ 	printf("                           HC for human against computer.\n");
+ 	printf("                           CH for computer against human.\n"); 
+ 	printf("                              Same as HC but computer starts.\n");
+ 	printf("                           CC for computer against computer.\n");
+ 	printf("                           HH for human against human.\n\n");
+ 	printf(" If you just hit enter your last command will be repeated.\n");
+ 	printf("\n");
+ }
+ 
+ enum
+ {
+ 	 GAME_HC = 1,
+ 	 GAME_HH
+ };
+ 
+ int parseCords(char *str)
+ {
+ 	 if(((*str >= 'a' && *str <= 'i') || 
+ 		 (*str >= 'A' && *str <= 'I')) && (str[1] >= '1' && str[1] <= '9'))
+ 	 {
+ 		  int x, y;
+ 
+ 		  if(*str >= 'a' && *str <= 'i')
+ 			   x = *str - 'a';
+ 		  else if(*str >= 'A' && *str <= 'I')
+ 			   x = *str - 'A';
+ 		  else
+ 			   return -1;
+ 
+ 		  y = str[1] - '1';
+ 
+ 		  return getHexxagonIndex(x + 1, y + 1);
+ 	 }
+ 	 
+ 	 return -1;
+ }
+ 
+ int main(int argc, char *argv[])
+ {
+ 	int quit = 0;
+ 	
+ 	int mode = 1;
+ 	
+ 	int level = 4;
+ 	int time = 12;
+ 	
+ 	printf("Hexxagon board game.\n");
+ 	printf("Copyright 2001.\n");
+ 	printf("Erik Jonsson.\n");
+ 	printf("Type \"copyright\" to see the copyright notice.\n\n");
+ 	
+ 	HexxagonGame *game = new HexxagonGame();
+ 	game->displayText();
+ 	
+ 	char *input = 0;
+ 	
+ 	while(!quit)
+ 	{
+ 		char *tmp = readline("Hexxagon (\"help\" for help):");
+ 		stripFromDblSpace(tmp);
+ 		
+ 		int len = strlen(tmp);
+ 		if(len && tmp[len - 1] == ' ')
+ 			tmp[len - 1] = 0;
+ 		
+ 		if(*tmp == 0)
+ 		{
+ 			if(input)
+ 				printf("Repeating last command.\n");
+ 			free(tmp);
+ 		}
+ 		else
+ 		{
+ 			free(input);
+ 			input = tmp;
+ 		}
+ 		
+ 		if(!input)
+ 			continue;
+ 		
+ 		if(!strcasecmp("quit", input) || !strcasecmp("exit", input))
+ 		{
+ 			quit = 1;
+ 		}
+ 		else if(!strcasecmp("help", input))
+ 			printHelp();
+ 		else if(!strcasecmp("copyright", input))
+ 			printCopy();
+ 		else if(!strncasecmp("level ", input, 6))
+ 		{
+ 			if(!(isdigit(input[6]) && input[7] == 0))
+ 				printf("Invalid input to command \"level\".\nValid values are 0-9.\n");
+ 			else
+ 				level = input[6] - '0';
+ 		}
+ 		else if(!strcasecmp("level", input))
+ 			printf("The search level is set to: %i.\n", level);
+ 		else if(!strncasecmp("time ", input, 5))
+ 		{
+ 			char *cp = input + 5;
+ 			
+ 			while(isdigit(*cp))
+ 				cp++;
+ 			
+ 			if(cp == input + 5 || (*cp != 0 && !((*cp == ' ') && *(cp + 1) == 0)))
+ 				printf("Syntax: time [number]\n");
+ 			else
+ 				time = atoi(input + 5);
+ 		}
+ 		else if(!strcasecmp("time", input))
+ 			printf("The search time is set to %i sec.\n", time);
+ 		else if(!strcasecmp("board", input))
+ 			game->displayText();
+ 		else if(!strcasecmp("undo", input))
+ 		{
+ 			if(game->prev())
+ 				printf("No more moves left to undo!\n");
+ 			else
+ 				game->displayText();
+ 		}
+ 		else if(!strcasecmp("redo", input))
+ 		{
+ 			if(game->next())
+ 				printf("There is no move to redo!\n");
+ 			else
+ 				game->displayText();
+ 		}
+ 		else if(!strcasecmp("hint", input))
+ 		{
+ 			game->computerMove(level, 0, time * 1000);
+ 			game->displayText();
+ 			
+ 			if(mode != GAME_HH)
+ 			{
+ 				 game->computerMove(level, 0, time * 1000);
+ 				 game->displayText();							
+ 			} 
+ 		}
+ 		else if(!strncasecmp("load ", input, 5))
+ 		{
+ 			int ret = game->loadGame(input + 5);
+ 			if(ret == 0)
+ 			{
+ 				printf("Game loaded.\n");
+ 				game->displayText();
+ 			}
+ 			else if(ret == -1)
+ 				printf("Error opening load-file!\n");
+ 			else if(ret == -3)
+ 				printf("Unknown file format.\n");
+ 			else
+ 				printf("Error reading from load-file!\n");
+ 		}
+ 		else if(!strcasecmp("load", input))
+ 			printf("The load command needs a filename as argument.\n");
+ 		else if(!strncasecmp("save ", input, 5))
+ 	   {
+ 		   int ret = game->saveGame(input + 5);
+ 		   if(ret == 0)
+ 			   printf("Game saved.\n");
+ 		   else if(ret == -1)
+ 			   printf("Error opening save-file!\n");
+ 		   else
+ 				 printf("Error writing to save-file!\n");
+ 	   }
+ 		else if(!strcasecmp("save", input))
+ 			printf("The save command needs a filename as argument.\n");
+ 		else if(!strncasecmp("newgame ", input, 8))
+ 		{
+ 			if(((input[8] == 'c' || input[8] == 'C') || (input[8] == 'h' || input[8] == 'H')) &&
+ 			   ((input[9] == 'c' || input[9] == 'C') || (input[9] == 'h' || input[8] == '9')) &&
+ 			   (input[10] == 0 || (input[10] == ' ' && input[11] == 0))) 
+ 			{
+ 				delete game;
+ 				game = new HexxagonGame();
+ 				game->displayText();
+ 				
+ 				if((input[8] == 'h' || input[8] == 'H') &&
+ 					(input[9] == 'c' || input[9] == 'C'))
+ 					mode = GAME_HC;
+ 				else if((input[8] == 'c' || input[8] == 'C') &&
+ 						(input[9] == 'h' || input[9] == 'H'))
+ 				{
+ 					game->computerMove(level, 0, time * 1000);
+ 					game->displayText();
+ 					mode = GAME_HC;
+ 				}
+ 				else if((input[8] == 'h' || input[8] == 'H') &&
+ 						(input[9] == 'h' || input[9] == 'H'))
+ 					mode = GAME_HH;
+ 				else if((input[8] == 'c' || input[8] == 'C') &&
+ 						(input[9] == 'c' || input[9] == 'C'))
+ 				{
+ 					while(!game->endOfGame())
+ 					{
+ 						game->computerMove(level, 0, time * 1000);
+ 						game->displayText();
+ 					}
+ 					
+ 					mode = GAME_HC;
+ 				}
+ 				else
+ 					printf("You have found a bug in Hexxagon! This code should never be called!!\n");
+ 			}
+ 			else
+ 				printf("Syntax: newgame HC/CH/CC/HH\n");
+ 		}
+ 		else if(!strcasecmp("newgame", input))
+ 		{
+ 			 printf("Syntax: newgame HC/CH/CC/HH\n");
+ 		}
+ 		else if(!strncasecmp("jump ", input, 5) ||
+ 				!strncasecmp("j ", input, 2))
+ 		{
+ 			 char *cp = input;
+ 			 
+ 			 if(!strncasecmp("j ", input, 2))
+ 				  cp += 2;
+ 			 else
+ 				  cp += 5;
+ 
+ 			 HexxagonMove move;
+ 
+ 			 int len = strlen(cp);
+ 			 if(len == 5)
+ 			 {
+ 				  move.from = parseCords(cp);
+ 				  move.to = parseCords(cp + 3);
+ 			 } else if(len == 4)
+ 			 {
+ 				  move.from = parseCords(cp);
+ 				  move.to = parseCords(cp + 2);
+ 			 }
+ 			 else
+ 				  move.from = -1;
+ 
+ 			 if(move.from != -1 && move.to != -1)
+ 			 {
+ 				  if(game->isMoveValid(move))
+ 				  {
+ 					   game->applyMove(move);
+ 					   game->displayText();							
+ 					   
+ 					   if(mode != GAME_HH)
+ 					   {
+ 							game->computerMove(level, 0, time * 1000);
+ 							game->displayText();							
+ 					   } 
+ 				  }
+ 				  else
+ 					   printf("Illegal move!\n");
+ 			 } 
+ 			 else
+ 			 {
+ 				  if(len == 5)
+ 				  {
+ 					   if(cp[2] == ' ')
+ 							printf("Bad cordinate.\n");
+ 					   else
+ 							printf("Syntax: jump [FROM][TO]\nEg. \"jump a4b4\"\n");
+ 				  }
+ 				  else if(len == 4)
+ 					   printf("Bad cordinate.\n");
+ 				  else
+ 					   printf("Syntax: jump [FROM][TO]\nEg. \"jump a4b4\"\n");
+ 			 }
+ 		}
+ 		else if(!strcasecmp("jump", input) ||
+ 				!strcasecmp("j", input))
+ 		{
+ 			 printf("Syntax: jump [FROM][TO]\nEg. \"jump a4b4\"\n");
+ 		}
+ 		else if(!strncasecmp("clone ", input, 6) ||
+ 				!strncasecmp("c ", input, 2))
+ 		{
+ 			 char *cp = input;
+ 			 
+ 			 if(!strncasecmp("c ", input, 2))
+ 				  cp += 2;
+ 			 else
+ 				  cp += 6;
+ 
+ 			 HexxagonMove move;
+ 			 
+ 			 if(strlen(cp) == 2)
+ 			 {
+ 				  move.to = parseCords(cp);
+ 				  move.from = move.to;
+ 
+ 				  if(move.to != -1)
+ 				  {
+ 					   if(game->isMoveValid(move))
+ 					   {
+ 							game->applyMove(move);
+ 							game->displayText();							
+ 							
+ 							if(mode != GAME_HH)
+ 							{
+ 								 game->computerMove(level, 0, time * 1000);
+ 								 game->displayText();							
+ 							} 
+ 					   }
+ 					   else
+ 							printf("Illegal move!\n");
+ 				  }
+ 				  else
+ 					   printf("Invalid cordinate.\n");
+ 			 }
+ 			 else
+ 				  printf("Syntax: clone [TO]\nEg. \"clone b4\"\n");
+ 			 
+ 		}		
+ 		else if(!strcasecmp("clone", input) ||
+ 				!strcasecmp("c", input))
+ 		{
+ 			 printf("Syntax: clone [TO]\nEg. \"clone b4\"\n");
+ 		}
+ 		else
+ 			printf("Unknown command, try \"help\" for a list of commands.\n");
+ 	}
+ 	
+ 	free(input);
+ }


Index: llvm-test/MultiSource/Applications/hexxagon/hexxagonboard.cpp
diff -c /dev/null llvm-test/MultiSource/Applications/hexxagon/hexxagonboard.cpp:1.1
*** /dev/null	Fri Sep 10 09:26:05 2004
--- llvm-test/MultiSource/Applications/hexxagon/hexxagonboard.cpp	Fri Sep 10 09:25:52 2004
***************
*** 0 ****
--- 1,435 ----
+ /*
+  * Hexxagon board game.
+  * Copyright (C) 2001 Erik Jonsson.
+  * 
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * 
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+  * 
+  * Email erik at nesqi.homeip.net
+  * 
+  */
+ 
+ #include "hexxagonboard.h"
+ #include "hexxagonmove.h"
+ #include <iostream>
+ #include <stdlib.h>
+ 
+ using namespace std;
+ 
+ BitBoard64 *clone_lookups = 0; 
+ BitBoard64 *jump_lookups = 0; 
+ 
+ int getHexxagonIndex(int x, int y)
+ {
+ 	int no;
+ 
+ 	if(x > 0 && x < 10 && y > 0 && y < 10)
+ 	{
+ 		if(y < 5)
+ 			if(x > (9 - (5 - y)))
+ 				return -1;
+ 
+ 		if(y > 5)
+ 			if(x <= (y - 5))
+ 				return -1;
+ 	  
+ 		no = x+y*9 - 10;
+ 	  
+ 		if(y > 1) no -= 4;
+ 		if(y > 2) no -= 3;
+ 		if(y > 3) no -= 2;
+ 		if(y > 4) no -= 1;
+ 		if(y > 5) no -= 1;
+ 		if(y > 6) no -= 2;
+ 		if(y > 7) no -= 3;
+ 		if(y > 8) no -= 4;
+ 	  
+ 		return no;
+ 	}
+ 
+ 	return -1;
+ }
+ 
+ void initCloneLookups()
+ {
+ 	clone_lookups = new BitBoard64[61];
+ 	
+ 	int no = 0;
+ 
+ 	for(int i = 0; i < 61; i++)
+ 		clone_lookups[i] = BitBoard64(0,0);
+ 
+ 	// Clone. 
+ 	for(int y = 1; y <= 9; y++)
+ 	{
+ 		for(int x = 1; x <= 9; x++)
+ 		{
+ 			int out = 0;
+ 			
+ 			if(x > 0 && x < 10 && y > 0 && y < 10)
+ 			{
+ 				if(y < 5)
+ 					if(x > (9 - (5 - y)))
+ 						out = 1;
+ 				
+ 				if(y > 5)
+ 					if(x <= (y - 5))
+ 						out = 1;
+ 			}
+ 			
+ 			if(!out)
+ 			{
+ 				clone_lookups[no].setBit(getHexxagonIndex(x-1, y-1));
+ 				clone_lookups[no].setBit(getHexxagonIndex(x  , y-1));
+ 				clone_lookups[no].setBit(getHexxagonIndex(x-1, y  ));
+ 				clone_lookups[no].setBit(getHexxagonIndex(x+1, y  ));
+ 				clone_lookups[no].setBit(getHexxagonIndex(x  , y+1));
+ 				clone_lookups[no].setBit(getHexxagonIndex(x+1, y+1));
+ 				no++;
+ 			}
+ 		} 
+ 	}
+ }
+ 
+ void initJumpLookups()
+ {
+ 	jump_lookups = new BitBoard64[61];
+ 	
+ 	int no = 0;
+ 
+ 	for(int i = 0; i < 61; i++)
+ 		jump_lookups[i] = BitBoard64(0,0);
+ 
+ 	// Jump.
+ 	for(int y = 1; y <= 9; y++)
+ 	{
+ 		for(int x = 1; x <= 9; x++)
+ 		{
+ 			int out = 0;
+ 			
+ 			if(x > 0 && x < 10 && y > 0 && y < 10)
+ 			{
+ 				if(y < 5)
+ 					if(x > (9 - (5 - y)))
+ 						out = 1;
+ 				
+ 				if(y > 5)
+ 					if(x <= (y - 5))
+ 						out = 1;
+ 			}
+ 			
+ 			if(!out)
+ 			{
+ 				jump_lookups[no].setBit(getHexxagonIndex(x-2, y-2));
+ 				jump_lookups[no].setBit(getHexxagonIndex(x-1, y-2));
+ 				jump_lookups[no].setBit(getHexxagonIndex(  x, y-2));
+ 				jump_lookups[no].setBit(getHexxagonIndex(x-2, y-1));
+ 				jump_lookups[no].setBit(getHexxagonIndex(x+1, y-1));
+ 				jump_lookups[no].setBit(getHexxagonIndex(x-2, y  ));
+ 				jump_lookups[no].setBit(getHexxagonIndex(x+2, y  ));
+ 				jump_lookups[no].setBit(getHexxagonIndex(x-1, y+1));
+ 				jump_lookups[no].setBit(getHexxagonIndex(x+2, y+1));
+ 				jump_lookups[no].setBit(getHexxagonIndex(x  , y+2));
+ 				jump_lookups[no].setBit(getHexxagonIndex(x+1, y+2));
+ 				jump_lookups[no].setBit(getHexxagonIndex(x+2, y+2));
+ 				no++;
+ 			}
+ 		}
+ 	}
+ }
+ 
+ HexxagonBoard::HexxagonBoard(const HexxagonBoard &copy)
+ {
+ 	board = copy.board;
+ 	color = copy.color;
+ }
+ 
+ HexxagonBoard HexxagonBoard::operator=(const HexxagonBoard &right)
+ {
+ 	color = right.color;
+ 	board = right.board;
+ 
+ 	return *this;
+ }
+ 
+ void HexxagonBoard::init(void)
+ {
+ 	board = BitBoard64(0,0);
+ 	color = BitBoard64(0,0);
+ 
+ 	board.setBit( 0); color.setBit(0);
+     board.setBit(34); color.setBit(34);
+ 	board.setBit(56); color.setBit(56);
+ 	board.setBit( 4);
+ 	board.setBit(26);
+ 	board.setBit(60);
+ }
+ 
+ int HexxagonBoard::countBricks(int player)
+ {
+ 	int good = 0, bad = 0;
+ 
+ 	for(int i = 0; i < 61; i++)
+ 	{
+ 		if(board.getBit(i))
+ 		{
+ 			if(color.getBit(i))
+ 				good++;
+ 			else
+ 				bad++;
+ 		}
+ 	}
+ 
+ 	if(player == 0)
+ 		return good - bad;
+ 	else if(player == 1)
+ 		return good;
+ 	else if(player == 2)
+ 		return bad;
+ 	
+ 	return 0;
+ }
+ 
+ int HexxagonBoard::evaluate(void)
+ {
+ 	int good = 0; 
+ 	int bad = 0;
+ 	int count = 0;
+ 
+ 	for(int i = 0; i < 61; i++)
+ 	{
+ 		if(board.getBit(i))
+ 		{
+ 			count++;
+ 			if(color.getBit(i))
+ 				good++;
+ 			else
+ 				bad++;
+ 		}
+ 	}
+     
+ 	int score = good - bad;
+ 	
+ 	if(good == 0 || bad == 0 || count == 61) /* Game is over... */
+ 	{
+ 		if(good == 0)
+ 			score -= SCR_WIN;
+ 
+ 		if(bad == 0)
+ 			score += SCR_WIN;
+ 
+ 		if(count == 61)
+ 		{
+ 			if(good > bad)
+ 				score += SCR_WIN;
+ 			
+ 			if(good <= bad)
+ 				score -= SCR_WIN;
+ 		}
+ 	}
+ 
+ 	return score;
+ }
+ 
+ int HexxagonBoard::getHexxagon(int i)
+ {
+ 	if(board.getBit(i))
+ 	{
+ 		if(color.getBit(i))
+ 			return pl1;
+ 		else
+ 			return pl2;
+ 	} else
+ 		return empty;
+ }
+ 
+ int HexxagonBoard::applyMove(HexxagonMove &move)
+ {
+ 	board.setBit(move.to);
+ 	color.setBit(move.to);
+ 		
+ 	color = color | clone_lookups[move.to];
+ 
+ 	if(move.from != move.to) // Jump.
+ 		board.unSetBit(move.from);
+ 	
+ 	color = ~color;
+ 
+ 	return 0;
+ }
+ 
+ int HexxagonBoard::isMoveValid(HexxagonMove &move)
+ {
+ 	 BitBoard64 mine = color & board;
+ 
+ 	 if(!board.getBit(move.to))
+ 	 {
+ 		  if(move.from == move.to) // clone
+ 		  {
+ 			   if(mine & clone_lookups[move.to])
+ 					return 1;
+ 		  }
+ 		  else // Jump
+ 		  {
+ 			   BitBoard64 tmp(0,0);
+ 			   tmp.setBit(move.from);
+ 
+ 			   if(tmp & jump_lookups[move.to] & mine)
+ 					return 1;
+ 		  }
+ 	 }
+ 		  
+ 	 return 0;
+ }
+ 
+ HexxagonMoveList *HexxagonBoard::generateMoveList()
+ {
+ 	HexxagonMoveList *list = new HexxagonMoveList();
+ 
+ 	if(!list)
+ 	{
+ 		printf("Out of memory !\n");
+ 		exit(-1);
+ 	}
+ 
+ 	for(int i = 0; i < 61; i++)
+ 	{
+ 		if(!board.getBit(i)) // Found place to clone / jump.
+ 		{
+ 			if(color.operator&((board.operator&(clone_lookups[i])))) // Clone.
+ 			{
+ 				HexxagonMove move = HexxagonMove(i);
+ 				list->addMove(move);
+ 			}
+ 			
+ 			BitBoard64 moves;
+ 			if((moves = ((board & jump_lookups[i]) & color))) // Jump.
+ 			{
+ 				for(int j = 0; j < 61; j++)
+ 				{
+ 					if(moves.getBit(j))
+ 					{
+ 						HexxagonMove move = HexxagonMove(j, i);
+ 						list->addMove(move);
+ 					}
+ 				}
+ 			}
+ 		}
+ 	}
+ 
+ 	if(list->getNrMoves())
+ 		return list;
+ 
+ 	delete list;
+ 	return 0;
+ }
+ 
+ int HexxagonBoard::endOfGame()
+ {
+ 	HexxagonMoveList *movelist;
+ 	
+ 	movelist = generateMoveList();
+ 
+ 	if(!movelist)
+ 		return 1;
+ 
+ 	delete movelist;
+ 	
+ 	return 0;
+ }
+ 
+ int HexxagonBoard::computerMove(int depth, void (*callback)(), int maxtime)
+ {
+ 	HexxagonMoveList *movelist;
+ 
+ 	if(!(movelist = generateMoveList()))
+ 	{
+ 		printf("No more moves.\n");
+ 		return -1;
+ 	} 
+ 
+ 	movelist->scoreAllMoves(*this, depth, callback, maxtime);
+ 	applyMove(*(movelist->getBestMove()));
+ 	
+ 	delete movelist;
+ 	
+ 	return 0;
+ }
+ 
+ int HexxagonBoard::readFromFile(FILE *file)
+ {
+ 	if(color.readFromFile(file) || board.readFromFile(file))
+ 		return -1;
+ 	else
+ 		return 0;
+ }
+ 
+ int HexxagonBoard::writeToFile(FILE *file)
+ {
+ 	if(color.writeToFile(file) || board.writeToFile(file))
+ 		return -1;
+ 	else
+ 		return 0;
+ }
+ 
+ void HexxagonBoard::displayBoardText(int turn)
+ {
+ 	BitBoard64 c(color);
+ 
+ 	if(!turn)
+ 		c = ~c;
+ 
+ 	cout << "         A B C D E F G H I\n";
+ 	cout << "        / / / / / / / / /\n";
+ 
+ 	for(int y = 1; y < 10; y++)
+ 	{
+ 		cout << y << "- ";
+ 
+ 		if(y < 5)
+ 		{
+ 			for(int off = 0; off < (5 - y); off++)
+ 				cout << " ";
+ 		}
+ 
+ 		for(int x = 1; x < 10; x++)
+ 		{
+ 			int no;
+ 
+ 			if((no = getHexxagonIndex(x, y)) == -1)
+ 				cout << " ";
+ 			else 
+ 			{
+ 				if(board.getBit(no))
+ 				{
+ 					if(c.getBit(getHexxagonIndex(x, y)))
+ 						cout << "x ";
+ 					else
+ 						cout << "o ";
+ 				} else
+ 					cout << ". ";
+ 			}
+ 		}
+ 		cout << "\n";
+ 	}
+ 	
+ 	int empty = 61 - ((turn ? countBricks(1) : countBricks(2)) + 
+ 					  (turn ? countBricks(2) : countBricks(1)));
+ 	
+ 	cout << "\nBricks: x " << (turn ? countBricks(1) : countBricks(2));
+ 	cout << ", o " << (turn ? countBricks(2) : countBricks(1));
+ 	cout <<	". Empty " << empty << ".\n";
+ 	cout << "Next to move: " << (turn ? "x" : "o");
+ 	cout << (endOfGame() ? ", Game over." : "") << "\n";
+ }


Index: llvm-test/MultiSource/Applications/hexxagon/hexxagonboard.h
diff -c /dev/null llvm-test/MultiSource/Applications/hexxagon/hexxagonboard.h:1.1
*** /dev/null	Fri Sep 10 09:26:05 2004
--- llvm-test/MultiSource/Applications/hexxagon/hexxagonboard.h	Fri Sep 10 09:25:53 2004
***************
*** 0 ****
--- 1,84 ----
+ /*
+  * Hexxagon board game.
+  * Copyright (C) 2001 Erik Jonsson.
+  * 
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * 
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+  * 
+  * Email erik at nesqi.homeip.net
+  * 
+  */
+ 
+ #ifndef _HEXXAGONBOARD_H
+ #define _HEXXAGONBOARD_H
+ 
+ #include "bitboard64.h"
+ 
+ class HexxagonMove;
+ class HexxagonMoveList;
+ 
+ enum 
+ {
+ 	SCR_WIN = 20000,
+ 	SCR_INFINITY = 32000
+ };
+ 
+ /* Hexxagon type */
+ enum 
+ {
+ 	pl1 = 1,
+ 	pl2,
+ 	empty,
+ 	removed
+ };
+ 
+ int getHexxagonIndex(int x, int y);
+ void initCloneLookups();
+ void initJumpLookups();
+ 
+ class HexxagonBoard
+ {
+  public:
+ 
+ 	HexxagonBoard(void) {};
+ 	HexxagonBoard(const HexxagonBoard &copy);
+ 
+ 	void init(void);
+ 	int evaluate(void);
+ 	int countBricks(int player);
+ 	int getHexxagon(int i);
+ 	int applyMove(HexxagonMove &move);
+ 
+ 	HexxagonMoveList *generateMoveList();
+ 
+ 	int computerMove(int depth, void (*callback)(), int maxtime);
+ 	int endOfGame();
+ 	int isMoveValid(HexxagonMove &move);
+ 
+ 	BitBoard64 getBBBoard() {return board;};
+ 	BitBoard64 getBBColor() {return color;};
+ 
+ 	HexxagonBoard operator=(const HexxagonBoard &right);
+ 
+ 	int readFromFile(FILE *file);
+ 	int writeToFile(FILE *file);
+ 
+ 	void displayBoardText(int turn);
+ 
+  protected:
+ 	BitBoard64 board;
+ 	BitBoard64 color;
+ };
+ 
+ #endif


Index: llvm-test/MultiSource/Applications/hexxagon/hexxagongame.cpp
diff -c /dev/null llvm-test/MultiSource/Applications/hexxagon/hexxagongame.cpp:1.1
*** /dev/null	Fri Sep 10 09:26:05 2004
--- llvm-test/MultiSource/Applications/hexxagon/hexxagongame.cpp	Fri Sep 10 09:25:53 2004
***************
*** 0 ****
--- 1,273 ----
+ /*
+  * Hexxagon board game.
+  * Copyright (C) 2001 Erik Jonsson.
+  * 
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * 
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+  * 
+  * Email erik at nesqi.homeip.net
+  * 
+  */
+ 
+ #include "hexxagongame.h"
+ #include <netinet/in.h>
+ #include <string.h>
+ 
+ extern BitBoard64 *clone_lookups; 
+ extern BitBoard64 *jump_lookups; 
+ 
+ HexxagonGame::HexxagonGame()
+ {
+ 	if(!clone_lookups)
+ 		initCloneLookups();
+ 
+ 	if(!jump_lookups)
+ 		initJumpLookups();
+ 
+ 	GameList *tmp = new GameList(0);
+ 
+ 	tmp->init(); 
+ 
+ 	first = tmp; 
+ 	curr = tmp;
+ 
+ 	turn = 1;
+ }
+ 
+ int HexxagonGame::next()
+ {
+ 	if(curr->next)
+ 	{
+ 		turn = !turn;
+ 		curr = curr->next;
+ 		return 0;
+ 	} 
+ 	
+ 	return -1;
+ }
+ 
+ int HexxagonGame::prev()
+ {
+ 	if(curr->prev)
+ 	{
+ 		turn = !turn;
+ 		curr = curr->prev;
+ 		return 0;
+ 	}
+ 	
+ 	return -1;
+ }
+ 
+ void HexxagonGame::reset()
+ {
+ 	while(!prev())
+ 		;
+ 	
+ 	destroyRest();
+ }
+ 
+ void HexxagonGame::destroyRest()
+ {
+ 	GameList *step = curr->next;
+    
+ 	while(step)
+ 	{
+ 		GameList *tmp = step;
+ 		delete step;
+ 		step = tmp->next;
+ 	}
+ 
+ 	curr->next = 0;
+ }
+ 
+ int HexxagonGame::applyMove(HexxagonMove &move)
+ {
+ 	GameList *tmp = new GameList(curr);
+ 	
+ 	tmp->HexxagonBoard::operator=(*curr);
+ 	
+ 	int ret = tmp->applyMove(move);
+ 		
+ 	if(!ret)
+ 	{
+ 		curr->next = tmp;
+ 		next();
+ 	}
+ 	else
+ 		delete tmp;
+ 
+ 	return ret;
+ }
+ 
+ int HexxagonGame::computerMove(int depth, void (*callback)(), int maxtime)
+ {
+ 	GameList *tmp = new GameList(curr);
+ 
+ 	tmp->HexxagonBoard::operator=(*curr);
+ 	
+ 	int ret = tmp->computerMove(depth, callback, maxtime);
+ 		
+ 	if(!ret)
+ 	{
+ 		curr->next = tmp;
+ 		next();
+ 	}
+ 	else
+ 		delete tmp;
+ 
+ 	return ret;
+ }
+ 
+ //  File format
+ //----------------
+ //  
+ //  Hex2agon 1.0\n
+ //  32bit networkorder integer : boards
+ //  datablocks....
+ //  EOF
+ 
+ int HexxagonGame::noBoards()
+ {
+ 	GameList *step = first;
+ 	int sum = 0;
+ 	
+ 	while(step)
+ 	{
+ 		sum++;
+ 		step = step->next;
+ 	}
+ 
+ 	return sum;
+ }
+ 
+ #define FILE_HDR "Hex2agon 1.1\n"
+ 
+ int HexxagonGame::loadGame(char *filename)
+ {
+ 	FILE *loadfile;
+ 
+ 	loadfile = fopen(filename, "rb");
+ 
+ 	if(!loadfile)
+ 		return -1;
+ 	
+ 	char str[64];
+ 	if(fread(str, strlen(FILE_HDR), 1, loadfile) != 1)
+ 	{
+ 		 fclose(loadfile);
+ 		 return -2;
+ 	}
+ 		
+ 	if(memcmp(str, FILE_HDR, strlen(FILE_HDR)))
+ 	{
+ 		 fclose(loadfile);
+ 		 return -3;
+ 	}
+ 
+ 	long int no;
+ 	if(fread(&no, sizeof(long int), 1, loadfile) != 1)
+ 	{
+ 		 fclose(loadfile);
+ 		 return -2;
+ 	}
+ 	
+ 	no = ntohl(no);
+ 
+ 	curr = first;
+ 	destroyRest();
+ 	delete first;
+ 	first = 0;
+ 	turn = 1;
+ 	while(no)
+ 	{
+ 		GameList *tmp;
+ 
+ 		if(first == 0)
+ 		{
+ 			tmp = new GameList(0);
+ 
+ 			first = tmp;
+ 			curr = tmp;
+ 		} 
+ 		else
+ 		{
+ 			tmp = new GameList(curr);
+ 			curr->next = tmp;
+ 			
+ 			next();
+ 		}
+ 
+ 		int ret = tmp->readFromFile(loadfile);
+ 
+ 		if(ret)
+ 		{
+ 			prev();
+ 			destroyRest();
+ 			return ret;
+ 		}
+ 		
+ 		no--;
+ 	}
+ 	
+ 	fclose(loadfile);
+ 
+ 	return 0;
+ }
+ 
+ int HexxagonGame::saveGame(char *filename)
+ {
+ 	FILE *savefile;
+ 
+ 	savefile = fopen(filename, "wb");
+ 
+ 	if(!savefile)
+ 		return -1;
+ 
+ 	if(fwrite(FILE_HDR, strlen(FILE_HDR), 1, savefile) != 1)
+ 	{
+ 		 fclose(savefile);
+ 		 return -2;
+ 	}
+ 
+ 	long int no;
+ 
+ 	no = htonl(noBoards());
+ 
+ 	// BUG ?? The size can be different.
+ 	if(fwrite(&no, sizeof(long int), 1, savefile) != 1)
+ 	{
+ 		 fclose(savefile);
+ 		 return -2;
+ 	}
+ 
+ 	GameList *step = first;
+ 	while(step)
+ 	{
+ 		if(step->writeToFile(savefile))
+ 		{
+ 			 fclose(savefile);
+ 			 return -2;
+ 		}
+ 
+ 		step = step->next;
+ 	}
+ 	
+ 	fclose(savefile);
+ 
+ 	return 0;
+ }
+ 
+ 
+ 
+ 


Index: llvm-test/MultiSource/Applications/hexxagon/hexxagongame.h
diff -c /dev/null llvm-test/MultiSource/Applications/hexxagon/hexxagongame.h:1.1
*** /dev/null	Fri Sep 10 09:26:05 2004
--- llvm-test/MultiSource/Applications/hexxagon/hexxagongame.h	Fri Sep 10 09:25:53 2004
***************
*** 0 ****
--- 1,74 ----
+ /*
+  * Hexxagon board game.
+  * Copyright (C) 2001 Erik Jonsson.
+  * 
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * 
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+  * 
+  * Email erik at nesqi.homeip.net
+  * 
+  */
+ 
+ #ifndef _HEXXAGONGAME_H
+ #define _HEXXAGONGAME_H
+ 
+ #include "hexxagonboard.h"
+ 
+ class GameList : public HexxagonBoard
+ {
+  public:
+ 	GameList(GameList *p) {prev = p; next = 0;};
+ 	
+ 	GameList *next;
+     GameList *prev;
+ };
+ 
+ class HexxagonGame
+ {
+  public:
+ 	HexxagonGame(); 
+ 	~HexxagonGame() {destroyRest(); delete first;};
+ 
+ 	int getTurn() {return turn;};
+ 
+ 	int next();
+ 	int prev();
+ 
+ 	void reset();
+ 	void destroyRest();
+ 
+ 	int applyMove(HexxagonMove &move);
+ 	int computerMove(int depth, void (*callback)(), int maxtime);
+ 
+ 	int noBoards();
+ 	
+ 	HexxagonBoard *getBoard() {return (HexxagonBoard*) curr; };
+ 
+ 	int endOfGame() {return curr->endOfGame();};
+ 	int isMoveValid(HexxagonMove &move){ return curr->isMoveValid(move);};
+ 
+ 	void displayText() {curr->displayBoardText(turn);};
+ 	
+ 	int saveGame(char *filename);
+ 	int loadGame(char *filename);
+ 
+  protected:
+ 	int turn;
+ 
+ 	GameList *first;
+ 	GameList *curr;
+ };
+ 
+ #endif // _HEXXAGONGAME_H
+ 


Index: llvm-test/MultiSource/Applications/hexxagon/hexxagonmove.cpp
diff -c /dev/null llvm-test/MultiSource/Applications/hexxagon/hexxagonmove.cpp:1.1
*** /dev/null	Fri Sep 10 09:26:06 2004
--- llvm-test/MultiSource/Applications/hexxagon/hexxagonmove.cpp	Fri Sep 10 09:25:53 2004
***************
*** 0 ****
--- 1,191 ----
+ /*
+  * Hexxagon board game.
+  * Copyright (C) 2001 Erik Jonsson.
+  * 
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * 
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+  * 
+  * Email erik at nesqi.homeip.net
+  * 
+  */
+ 
+ #include "hexxagonboard.h"
+ #include "hexxagonmove.h"
+ 
+ #include <sys/timeb.h>
+ #include <iostream>
+ #include <stdlib.h>
+ #include <string.h>
+ 
+ using namespace std;
+ 
+ void HexxagonMoveList::addMove(HexxagonMove &move)
+ {
+ 	if(!(nr_moves & 0xF)) /* Only check every 16:th (Extra speed) */
+ 	{
+ 		for(int i = NO_MOVES_BEGIN; i <= nr_moves; i *= 2)
+ 		{
+ 			if(nr_moves == i)
+ 			{
+ 				HexxagonMove *tmp = new HexxagonMove[i * 2];
+ 				memcpy(tmp, moves, i * sizeof(class HexxagonMove));
+ 				delete moves;
+ 				moves = tmp;
+ 			}
+ 		}
+ 	}
+ 
+  	moves[nr_moves] = move;
+ 	nr_moves++;
+ }
+ 
+ int compare(const void *mp1, const void *mp2)
+ {
+ 	return ((HexxagonMove*)mp2)->score - ((HexxagonMove*)mp1)->score;
+ }
+ 
+ void HexxagonMoveList::sortListQuick()
+ {
+ 	qsort(moves, nr_moves, sizeof(moves[0]), &compare);
+ }
+ 
+ void HexxagonMoveList::sortList()
+ {
+ 	int move = 1;
+ 
+ 	while(move)
+ 	{
+ 		move = 0;
+ 		for(int i = 0; i < (nr_moves - 1); i++)
+ 		{
+ 			if(moves[i].score < moves[i+1].score)
+ 			{
+ 				move = 1;
+ 				HexxagonMove tmp;
+ 				memcpy(&tmp, &moves[i], sizeof(HexxagonMove));
+ 				memcpy(&moves[i], &moves[i+1], sizeof(HexxagonMove));
+ 				memcpy(&moves[i+1], &tmp, sizeof(HexxagonMove));
+ 			} 
+ 		}
+ 	}
+ }
+ 
+ int getTime()
+ {
+ 	struct timeb tb;
+ 	
+ 	ftime(&tb);
+ 	return (tb.time * 1000) + tb.millitm;
+ }
+ 
+ HexxagonMove *HexxagonMoveList::getMove(int i)
+ {
+ 	return &moves[i];
+ }
+ 
+ int HexxagonMoveList::getNrMoves()
+ {
+ 	return nr_moves;
+ }
+ 
+ char hexx_count;
+ int alphaBeta(HexxagonBoard &board, int level, int alpha, int beta, void (*callback)())
+ {
+ 	int best = -SCR_INFINITY;
+ 
+ 	if(!level)
+ 		return board.evaluate();
+ 
+ 	HexxagonMoveList *moves = board.generateMoveList();
+ 
+ 	if(!moves) // The game is over.
+ 	{
+ 		int score = board.countBricks(0); // Add win or loss points to score.
+ 
+ 		if(score > 0)
+ 			return score + SCR_WIN;
+ 		else if(score < 0)
+ 			return score - SCR_WIN;
+ 		else
+ 			return board.evaluate();
+ 	}
+ 
+ 	hexx_count++;
+ 	if(!hexx_count && callback)
+ 		callback();
+ 
+ 	for(int i = 0; (i < moves->getNrMoves()) && (best < beta); i++)
+ 	{
+ 		if(best > alpha)
+ 			alpha = best;
+ 
+ 		HexxagonBoard newboard = HexxagonBoard(board);
+ 		newboard.applyMove(*(moves->getMove(i)));
+ 		int value = -alphaBeta(newboard, level - 1, -beta, -alpha, callback);
+ 
+ 		if(value > best)
+ 			best = value;
+ 	}     
+ 
+ 	delete moves;
+ 
+ 	return best;
+ }
+ 
+ void HexxagonMoveList::scoreAllMoves(HexxagonBoard board, int depth, void (*callback)(), int maxtime)
+ {
+ 	int t = getTime();
+ 
+ 	for(int i = 1; (i < depth) && (getTime() - t <= maxtime); i++)
+ 	{
+ 		int best  = -SCR_INFINITY;
+ 		int alpha = -SCR_INFINITY;
+ 		int beta  = SCR_INFINITY;
+ 
+ 		for(int j = 0; (j < getNrMoves()) && (getTime() - t <= maxtime) && (best < beta); j++)
+ 		{
+ 			if(best > alpha)
+ 				alpha = best;
+ 
+ 			HexxagonBoard newboard = HexxagonBoard(board);
+ 			newboard.applyMove(*getMove(j));
+ 			int value = -alphaBeta(newboard, i, -beta, -alpha, callback);
+ 			
+ 			getMove(j)->score = value;
+ 
+ 			if(value > best)
+ 				best = value;
+ 		}
+ 		
+ 		sortList();
+ 	}
+ 
+ #if 0
+ 	cout << "Move computed in " << ((double)getTime() - t) / (double)1000 << " seconds.\n";
+ #endif
+ }
+ 
+ HexxagonMove *HexxagonMoveList::getBestMove()
+ {
+ 	srandom(getTime());
+ 
+ 	if(nr_moves)
+ 		return getMove(0);
+ 	
+ 	return NULL;
+ }
+ 
+ 
+ 
+ 


Index: llvm-test/MultiSource/Applications/hexxagon/hexxagonmove.h
diff -c /dev/null llvm-test/MultiSource/Applications/hexxagon/hexxagonmove.h:1.1
*** /dev/null	Fri Sep 10 09:26:06 2004
--- llvm-test/MultiSource/Applications/hexxagon/hexxagonmove.h	Fri Sep 10 09:25:53 2004
***************
*** 0 ****
--- 1,66 ----
+ /*
+  * Hexxagon board game.
+  * Copyright (C) 2001 Erik Jonsson.
+  * 
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * 
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+  * 
+  * Email erik at nesqi.homeip.net
+  * 
+  */
+ 
+ #ifndef _HEXXAGONMOVE_H
+ #define _HEXXAGONMOVE_H
+ 
+ #include "hexxagonboard.h"
+ 
+ #define NO_MOVES_BEGIN 16
+ 
+ class HexxagonBoard;
+ 
+ class HexxagonMove
+ {
+  public:
+ 	HexxagonMove() {};
+ 	HexxagonMove(int t) {from = t; to = t;};
+ 	HexxagonMove(int f, int t) {from = f; to = t;};
+ 
+ 	char from, to;
+ 	int score;
+ };
+ 
+ class HexxagonMoveList
+ {
+  public:
+ 	HexxagonMoveList() { moves = new HexxagonMove[NO_MOVES_BEGIN]; nr_moves = 0; };
+ 	~HexxagonMoveList() { delete moves; };
+  
+ 	void scoreAllMoves(HexxagonBoard board, int depth, void (*callback)(), int maxtime);
+ 	void sortList();
+ 	void sortListQuick(); /* Not used... (slower) */
+ 
+ 	int getNrMoves();
+ 
+ 	void addMove(HexxagonMove &move);
+ 	HexxagonMove *getMove(int i);
+ 	
+ 	HexxagonMove *getBestMove();
+ 
+  private:
+ 
+ 	int nr_moves;
+ 	HexxagonMove *moves;
+ };
+ 
+ #endif // _HEXXAGONMOVE_H


Index: llvm-test/MultiSource/Applications/hexxagon/input
diff -c /dev/null llvm-test/MultiSource/Applications/hexxagon/input:1.1
*** /dev/null	Fri Sep 10 09:26:06 2004
--- llvm-test/MultiSource/Applications/hexxagon/input	Fri Sep 10 09:25:53 2004
***************
*** 0 ****
--- 1,3 ----
+ newgame cc
+ quit
+ 


Index: llvm-test/MultiSource/Applications/hexxagon/libhexx.h
diff -c /dev/null llvm-test/MultiSource/Applications/hexxagon/libhexx.h:1.1
*** /dev/null	Fri Sep 10 09:26:06 2004
--- llvm-test/MultiSource/Applications/hexxagon/libhexx.h	Fri Sep 10 09:25:53 2004
***************
*** 0 ****
--- 1,26 ----
+ /*
+  * Hexxagon board game.
+  * Copyright (C) 2001 Erik Jonsson.
+  * 
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * 
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+  * 
+  * Email erik at nesqi.homeip.net
+  * 
+  */
+ 
+ #include "bitboard64.h"
+ #include "hexxagonmove.h"
+ #include "hexxagonboard.h"
+ #include "hexxagongame.h"






More information about the llvm-commits mailing list