Writing a GamesCrafters Game in C - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Writing a GamesCrafters Game in C

Description:

Download the gamesman package for Unix. As of right now, there is no version for Windows. ... website has the 10-step tutorial for writing a game module. ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 18
Provided by: judy4
Category:

less

Transcript and Presenter's Notes

Title: Writing a GamesCrafters Game in C


1
Writing a GamesCrafters Game in C
  • Monday, Sept. 22, 2003
  • Judy Chen

2
What well cover today
  • Quick introduction to C
  • Hash Functions
  • Sample game (Snake)

3
C versus Java
  • Local variables have to be at the top
  • No Boolean type
  • Structures
  • / /
  • printf(Foo is d and bar is f\n, 5, 3.5)
  • for loops syntax
  • variables arent initialized to anything
  • anywhere
  • Classes
  • / ... / or //
  • System.out.print

4
Arrays
  • C syntax for declaring an array is slightly
    different
  • int myarray5
  • int yourarray 1, 2, 3, 4, 5
  • Accessing stuff in arrays is the same
  • yourarray2 ?
  • yourarray2 3
  • Be careful b/c array bounds arent checked!

5
Pointers
  • Pointers represent raw memory addresses.

y
x
int x, y
?
?
y
x
y 5
?
5
Note that x still hasnt been initialized.
6
Pointers (contd)
  • Use the operator to get the address of a
    variable.

y
x
x y
5
  • Use the operator to dereference a pointer.

y
x
x 7
7
7
GamesCrafters
  • Download the gamesman package for Unix. As of
    right now, there is no version for Windows.
    http//www.cs.berkeley.edu/ddgarcia/research/game
    theory/current
  • The GamesCrafters website has the 10-step
    tutorial for writing a game module.
  • http//www.cs.berkeley.edu/ddgarcia/software/gam
    esman

8
Hash Functions
  • A hash function takes your board position and
    converts it into a number.
  • Each board position will have a unique number
    that it is hashed into.
  • Youll need a hash function and an unhash
    function, which will take a number and give you
    the board position.

9
Hashing Tic Tac Toe
  • Ex Tic Tac Toe
  • 0 for a blank square
  • 1 for an X
  • 2 for an O

10
The Makefile
  • There are 4 places where you need to add your
    game.
  • Pick one of the current games (i.e. TTT) and
    every time you see that game, copy and paste it
    and change TTT to your game.

11
The Makefile change 1
  • TTT_EXE (BINDIR)/mttt
  • TTT_OBJ mttt.o
  • TTT_SO (LIBDIR)/libmttt.so

12
The Makefile change 2
  • text_all 1210_EXE TTT_EXE ...
  • so_all 1210_SO TTT_SO ...

13
The Makefile change 3
  • TTT_OBJ SOLVER_INCLUDE
  • TTT_EXE TTT_OBJ ...
  • TTT_SO TTT_OBJ ...

14
The Makefile change 4
  • At the very end of the makefile...
  • clean
  • rm f 1210_EXE 1210_OBJ ...
  • minimal
  • rm f 1210_OBJ TTT_OBJ ...

15
Compiling and running
  • Log on to rhombus.cs (the most lenient compiler)
  • Add your mgame.c code the gamesman/src directory
  • cd gamesman/src
  • make ?to compile
  • cd ../bin
  • ./mgame ?to execute

16
Functions youll have to write
  • GameSpecificMenu (maybe.. if you want to add
    Variants)
  • GetInitialPosition
  • DoMove
  • Primitive
  • PrintPosition
  • GenerateMoves
  • Hash and Unhash

17
Questions?
Write a Comment
User Comments (0)
About PowerShow.com