0% found this document useful (0 votes)
0 views

Chess Gaming and Graphics Using Open Source Tools

This paper discusses the development of a high-quality chess game using open-source tools, focusing on the Beowulf chess engine and SDL libraries to enhance its graphical and interactive features. It details the integration of 2-D and 3-D graphics, utilizing tools like Blender and OpenGL for improved visual effects and multi-threading for better performance. The resulting game is platform-independent and can be run on various operating systems, making it accessible for educational purposes and embedded systems.

Uploaded by

Prima Wirawan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Chess Gaming and Graphics Using Open Source Tools

This paper discusses the development of a high-quality chess game using open-source tools, focusing on the Beowulf chess engine and SDL libraries to enhance its graphical and interactive features. It details the integration of 2-D and 3-D graphics, utilizing tools like Blender and OpenGL for improved visual effects and multi-threading for better performance. The resulting game is platform-independent and can be run on various operating systems, making it accessible for educational purposes and embedded systems.

Uploaded by

Prima Wirawan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

International Conference on Computing, Engineering and Information

Chess Gaming and Graphics using Open-Source Tools

Tong Lai Yu
California State University
Department of Computer Science and Engineering
San Bernardino,
CA 92407

Abstract decades, there were quite a lot of research of chess gam-


ing[1,2]. However, the research mainly focused on the de-
This paper explores the use of open-source resources to velopment of effective algorithms that computer programs
create a high-quality chess game with 2-D and 3-D graph- can effectively execute in real time to play against humans.
ical features. In our project, the popular open-source com- Some research also explored the use of distributed com-
puter chess engine, Beowulf, is used as our chess engine. puting to build an effective chess engine. In this paper,
Beowulf is simple and straightforward to use but it is single- our concern is on how one can put together some exist-
threaded; we make use of the platform-independent SDL ( ing platform-independent open-source resources to create a
Simple DirectMedia Layer ) libraries to make the engine high-quality interactive video chess game. The open-source
multi-threaded so that it becomes more robust, and inter- programs or libraries that we have used in this project in-
active and can handle multimedia features. Some recent clude the chess game engine Beowulf[3,4], 3-D content cre-
developments in graphics including OpenGL Shading Lan- ation suite Blender[5], 3DS library 3dslib[6], Simple Di-
guage ( GLSL ), shadow casting, and texture mapping are rectMedia Layer ( SDL ) library[7], Mesa OpenGL and Op-
used to enhance the graphical features of the game. In some neGL Shading Language ( GLSL ) libraries[8]. The resulted
cases, Blender, a 3D content creation suite is used to create chess game is platform-independent and can be compiled
some graphical objects in 3D Max format that saves an ob- and run in popular computing systems such as MS Win-
ject as a composite of many meshes along with relevant in- dows, MAC OS X, Linux, and FreeBSD etc; it can be eas-
formation like lighting, camera position and UV mapping. ily adopted to run in many embedded hand-held devices like
A 3D Max object can then be easily parsed and processed iphones and other mobile phones.
by a C/C++ program by making use of the 3dslib library.
Graphical objects are also created by the technique of Sur-
face of Revolution, which makes the program more flexible 2. Multithreaded and Multimedia Chess Game
and faster to run; display list is employed to improve the Engine
execution speed of the program.
In our project, the chess game engine is based on Be-
owulf which was primarily developed by Colin Frayn at the
1. Introduction University of Birmingham, UK and Dann Corbit of USA[3].
To find a good move, Beowulf searches a game tree using
In recent years, video games have gained popularity in a the Negamax Search algorithm, which is a slightly variant
wide variety of applications, including entertainment, edu- formulation of minimax search[9,10] that relies on the zero-
cation, technology skill training, and prevention or cure of sum property of a two-player game. The game tree can
chronic diseases like Alzheimer’s disease or memory im- be enormously simplified by Alpha-Beta pruning[11]. Its
pairment. Video chess game is a typical video game exam- strength is estimated to be around 2300 ELO (International
ple that can be used in education and mental training. Chess Master Standard) on a fast computer.
itself is a good exercise for mind that helps develop mental Beowulf is written in standard C. However, it is text-
abilities like critical thinking, abstract reasoning, problem based and single-threaded. We employed functions of
solving, pattern recognition, strategic planning, and creative the Simple DirectMedia Layer ( SDL) library[7] to add
thinking. Indeed, chess is part of the curriculum in Russia 2D graphics, multi-threaded features and sound effects to
and some Eastern European countries. Over the past few the game engine. The SDL library is also written in C

978-0-7695-3538-8/09 $26.00 © 2009 IEEE 253


DOI 10.1109/ICC.2009.28
10.1109/ICCEIS.2009.28
and can be easily integrated with OpenGL; it is a cross-
platform multimedia library designed to provide low level
access to audio, keyboard, mouse, joystick, 3D hardware
via OpenGL, and 2D video framebuffer; it has been used
by MPEG playback software, emulators, and many popular
games. By making it multi-threaded, the chess engine be-
comes more robust and a lot more interactive, allowing mu-
sic to be played while a game is in progress. Sound or music
features can be incorporated in the game using the SDL li-
braries or the Open Audio Library ( OpenAL )[12,13]. The
C/C++ standard template library ( STL ) containers such as
vectors and queues can be conveniently used to record the
states of the game so that moves can be undone. Images
may be created using the open-source GNU Image Manip-
ulation Program ( GIMP )[14].
Figure 1 shows a sample screen display of the 2D chess
game built using STL, Beowulf and SDL graphical inter-
faces. ( At this point, OpenGL is not needed as the game
is only two-dimensional and SDL provides very efficient
graphics rendering mechanisms. ) The program can be
compiled and run in any OS that SDL supports, including
Linux, Windows, Windows CE, BeOS, MacOS, Mac OS X, Figure 1. Sample 2D Chess Game.
FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and
QNX. Besides testing the chess program in RedHat Linux,
we have also tested it in an Embedded Linux system running
with ARM-9 processor at about 120 MHz[15]. Because of
the direct-access graphical support of SDL, one does NOT
need X-Window in the embedded system to run the chess
program. The embedded version works similar to the reg-
ular version, except that all the graphical images are scaled
down by half because of the small screen display of embed-
ded systems.

The open-source graphics tools discussed can be also ap-


plied to the development of many simple 2D games. As an
Figure 2. Embedded Game of Bejeweled.
example, Figure 2 shows another popular multimedia game,
Bejeweled, that we have developed for an ARM-based em-
bedded system[16,17] in a very short time using these open- for all major operating systems under the GNU General
source tools. Public License. Using Blender, one can easily create 3D
graphics models consisting of objects like a chess board
or chess pieces with textures and lighting effects; a graph-
ics model can be saved as a mesh of polygons along with
relevant information like UV mapping, material properties,
3. Three Dimensional Graphics light sources and camera positions which can then be parsed
and processed by a program written in a high-level language
Very often, a high-quality chess program may incorpo- like C/C++ or Java. We have used the 3DS format[6], the
rate more fancy 3D graphics in the game. For instance, a native format of Autodesk’s 3D Studio MAX to process 3D
player may want to rotate the game board, view it at dif- models. The 3DS format has become an industry standard
ferent angles, zoom it, translate it, or deform certain chess for transferring models between 3D programs, or for storing
pieces during the game to create special entertaining effects. models for 3D resource catalogs. It can be easily converted
To achieve these, one must go beyond the SDL graphics and to collada[6], a new interchange file format for interactive
use more sophisticated graphical tools and programming 3D applications based on open standard XML schema. In-
techniques. In the project, we used Blender as our graph- stead of writing programs to parse 3DS files, we used an-
ics modeler to create 3D graphics models. Blender[5,18] other popular open-source library, 3dslib[6] to manage 3DS
is a free open source 3D content creation suite, available files. The following piece of C/C++ code shows how to ren-

254
der a 3DS model using the 3dslib library and OpenGL. quite straightforward. It uses the two OpenGL utility com-
------------------------------------------------------- mands, gluPerspective() and gluLookAt() and the cam-
struct Vertex { era information saved in the 3DS file to specify the view of
float x, y, z;
}; the graphics model. It also makes use of the information of
textures, material properties, normals and triangular meshes
void display_meshes ( Lib3dsFile *f )
{ saved in the file to render the 3D model. The only crucial
struct Vertex *vs, v; feature that is not shown is the use of lighting information
Lib3dsMesh *mesh;
contained in the 3DS file. Once a 3DS file is parsed, we can
Lib3dsMaterial *mat=0; //mesh materials apply any affine transformation to the image objects; we can
init_texture(); //initialize texture features
rotate, translate or zoom the chess board or any chess piece.
glEnable( GL_CULL_FACE ); The texture of an object can be easily changed with cus-
glCullFace ( GL_BACK );
Lib3dsNode *node; //3DS node tomized texture images. Lighting and cameras can be ad-
justed according to needs. Moreover, shadows and special
for ( int k = 0; k < f->nmeshes; ++k ) {
mesh = f->meshes[k]; shading effects can be added to the model using OpenGL
vs = getVertices(f->meshes[k]);//get a vertice of mesh Shading Language ( GLSL )[19], which basically has the
//calculate normal same syntax as C/C++ and has become a very popular tool
float (*normals)[3] = (float (*)[3]) in video game development.
malloc (3*3*sizeof(float) * mesh->nfaces);
lib3ds_mesh_calculate_face_normals ( mesh, normals ); This is a very good method of creating 3D interactive
for ( int i = 0; i < mesh->nfaces; ++i ) { graphics for a chess program if the program runs in a pow-
if (mat) { //set material properties
float s; erful computer. However, a realistic 3DS model created
glMaterialfv(GL_FRONT, GL_AMBIENT, mat->ambient ); by Blender usually consists of a numerous number of poly-
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat->diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat->specular); gon meshes and it is computing-intensive to process a large
s = pow(2, 10.0*mat->shininess); number of meshes. Such a model may not be appropriate
if (s>128.0)
s=128.0; to be run in slower devices like embedded systems. For
glMaterialf(GL_FRONT, GL_SHININESS, s); slower systems, a better method to generate 3D chess pieces
} //if ( mat )
//display the mesh is to create them using the technique of ”Surface of Revolu-
glBegin ( GL_TRIANGLES ); tion”[20], in which a 3D object is produced by first drawing
for ( int j = 0; j < 3; ++ j ) {
glNormal3fv(normals[3*i+j]); a profile and then rotating the profile about an axis in dis-
int ii = mesh->faces[i].index[j]; crete steps. In our project, we used B-spline curves to gener-
v = vs[ii];
if ( mesh->texcos ) //texture coordinates ate profiles that can efficiently generate 3D chess piece im-
glTexCoord2f(mesh->texcos[ii][0], ages and by revolving the profiles around the z-coordinate
mesh->texcos[ii][1]);
glVertex3fv( ( float*)&v ); axis.
} A B-spline curve with n control points and n blending
glEnd();
} //for i functions Nk,m (t) of order m is described by the following
free ( normals ); equation:
} //for k
n−1
free ( vs ); X
} P (u) = Pk Nk,m (u)
k=0
void display()
{ where P0 , ..., Pn−1 are the control points and the blending
Lib3dsCamera *camera;
Lib3dsFile *f = get3dsFile ( (char *) filename ); functions can be calculated recursively:
if ( f->ncameras > 0 ) {  
camera = f->cameras[0];
u − uk
Nk,m (u) = Nk,m−1 (u)
glMatrixMode ( GL_PROJECTION ); uk+m−1 − uk
glLoadIdentity();  
gluPerspective ( camera->fov, 1.0, uk+m − u
camera->near_range, camera->far_range ); + Nk+1,m−1 (u)
glMatrixMode ( GL_MODELVIEW ); uk+m − uk+1
glLoadIdentity();
gluLookAt(camera->position[0], camera->position[1], 
camera->position[2], camera->target[0], 1 if uk < u ≤ uk+1
camera->target[1], camera->target[2], 0, 1, 0 ); Nk,1 (u) =
}
0 otherwise
display_meshes ( f );
glFlush(); for k = 0, 1, ...., n - 1. In the above formulas,
glutSwapBuffers(); (u0 , u1 , ...., un+m−1 ) is a knot vector, which can be cal-
}
------------------------------------------------------- culated according to the following rules[20]:

One can see from the code that the rendering process is 1. There are totally n + m knots, denoted as

255
u0 , ..., un+m−1 very valuable resources for education institutions like some
2. First m knots, u0 , ..., um−1 all have value 0 campuses of California State University that have curricula
3. Knots um , ..., un−1 increases in increments of teaching video games, graphics and image processing. Re-
value 1, from 1 to n - m. lying on open source tools enables students to affordably
4. The final m knots, un , ..., un+m−1 are all equal to undertake development of video game software and other
n - m + 1. related multimedia projects for profit, which can fuel their
interest and hope even if the profit is insignificantly small.
Figure 3 shows a pawn that was generated using this
method; the pink squared dots are the control points used
Acknowledgments
to produce the profile and the pawn object is obtained by
revolving the profile around the z-axis. By adjusting the This research is supported by the CSUSB 2008 Summer
control points, one can easily adjust the shape of the object. POD funding. The author thanks Dr. David Turner for in-
Also, display-lists[20] can be used to speed up the render- troducing the 3DS and collada 3D file formats.
ing of these kind of objects. Generating image objects using
surface revolution also makes the program a lot more flexi- References
ble when it is run in a wide range of platforms. More slices
and steps can be used when it is run in a fast system to give [1] Colin Frayn and Carlos Justiniano, ” The ChessBrain Project
higher quality images. In embedded systems where the pro- Massively Distributed Chess Tree Search” in Advanced Intelligent
cessor speed is much slower, the number of slices and steps Paradigms in Computer Games, Springer Berlin / Heidelberg, p.92
used can be significantly reduced. - 115, 2007.
[2] Colin M. Frayn, Carlos Justiniano, Kevin Lew, ”ChessBrain
II A Hierarchical Infrastructure for Distributed Inhomogeneous
Speed-Critical Computation”, IEEE Symposium on Computa-
tional Intelligence and Games , Reno NV, May 2006.
[3] http://www.frayn.net/beowulf
[4] http://www.frayn.net/beowulf/theory.html
[5] http://www.blender.org
[6] http://www.lib3ds.org, http://www.collada.org
[7] http://www.libsdl.org
[8] http://www.mesa3d.org
[9] J. Pearl, Heuristics: Intelligent Search Strategies for Computer
Problem Solving, Addison-Wesley, 1984.
[10] N. J. Nilsson, Artificial Intelligence: A New Synthesis, Mor-
gan Kaufmann Publishers, Inc. 1998.
[11] Knuth, D. E., and Moore, R. W., ”An Analysis of Alpha-Beta
Pruning”. Artificial Intelligence Vol. 6, No. 4: 293 - 326, 1975.
[12] http://www.openal.org
[13] John R. Hall, Programming Linux Games, Linux Journal
Press, 2001.
Figure 3. Pawn generated by Surface Revolu- [14] http://www.gimp.org
tion. [15] A.N. Sloss, D. Symes, and C. Wright, ARM System Devel-
oper’s Guide, Elsevier Inc., 2004.
[16] T.L. Yu, ”Implementing a 16-bit Embedded Ogg Vorbis De-
coder”, Proceedings of ICCSA 2006, San Diego, June, 2006.
[17] T.L. Yu, ”Implementation of Video Player for Embedded Sys-
4. Conclusions tems”, Proceedings of IASTED on Signal and Image Processing,
p. 25-30, Honolulu, Hawaii, August 20-22, 2007.
In conclusion, one can utilize open-source resources to [18] http://the-labs.com/Blender/3DS-details.html
[19] R.J. Rost, OpenGL Shading Language, Second Edition, Ad-
develop a high-quality multimedia 3D graphics game like
dison Wesley, 2006.
chess which can run in different platforms including em- [20] F.S. Hill, and S.M. Kelly, Computer Graphics Using OpenGL,
bedded systems. The use of open-source tools significantly 3rd Edition, Prentice Hall, 2007.
shorten the development time and reduce the development [21] T.L. Yu, ”A Framework for Very High Performance Com-
cost to a minimum. The learning of the tools is a valuable pression of Table Tennis Video Clips”, Proceedings of IASTED on
education experience for a developer; the skill can be reused Signal and Image Processing, P.167-172, Kailua-Kona, Hawaii,
again to develop different types of video games or image August 18-20, 2008.
processing applications[21]. Therefore, these tools are also

256

You might also like