1 / 17

Writing a GamesCrafters Game in C

Writing a GamesCrafters Game in C. Monday, Sept. 22, 2003 Judy Chen. What we’ll cover today. Quick introduction to C Hash Functions Sample game (Snake). Local variables have to be at the top No Boolean type Structures /* … */ printf(“Foo is %d and bar is %f<br>”, 5, 3.5);

atalo
Download Presentation

Writing a GamesCrafters Game in C

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. What we’ll cover today • Quick introduction to C • Hash Functions • Sample game (Snake)

  3. 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 aren’t initialized to anything anywhere Classes /* ... */ or // System.out.print C versus Java

  4. Arrays • C syntax for declaring an array is slightly different: int myarray[5]; int yourarray[] = { 1, 2, 3, 4, 5 }; • Accessing stuff in arrays is the same: yourarray[2] = ? yourarray[2] = 3 • Be careful b/c array bounds aren’t checked!

  5. Pointers • Pointers represent raw memory addresses. x y int *x, y; ? ? x y y = 5; ? 5 Note that x still hasn’t been initialized.

  6. Pointers (cont’d) • Use the & operator to get the address of a variable. x y x = &y; 5 • Use the * operator to dereference a pointer. x y *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/gametheory/current • The GamesCrafters website has the 10-step tutorial for writing a game module. http://www.cs.berkeley.edu/~ddgarcia/software/gamesman

  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. • You’ll 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 you’ll have to write • GameSpecificMenu (maybe.. if you want to add Variants) • GetInitialPosition • DoMove • Primitive • PrintPosition • GenerateMoves • Hash and Unhash

  17. Questions?

More Related