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

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 3 More Syntax; Working with Objects.
Advertisements

Introduction to Java 2 Programming Lecture 5 Array and Collections.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Introduction to Programming Lecture 15. In Today’s Lecture Pointers and Arrays Manipulations Pointers and Arrays Manipulations Pointers Expression Pointers.
CS-1030 Dr. Mark L. Hornick 1 Constructors Copy Constructors.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Lab#1 (14/3/1431h) Introduction To java programming cs425
Java.  Java is an object-oriented programming language.  Java is important to us because Android programming uses Java.  However, Java is much more.
Defining classes and methods Recitation – 09/(25,26)/2008 CS 180 Department of Computer Science, Purdue University.
Introduction to C Programming CE Lecture 1 Introduction to C.
CS 61C L03 Introduction to C (1)Harvey / Wawrzynek Fall 2003 © UCB 8/29/2003  Brian Harvey ( John Wawrzynek  (Warznek) (
CSC Programming for Science Lecture 30: Pointers.
CS 61C L2 Introduction to C (1) A Carle, Summer 2006 © UCB inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 2: Introduction To C
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
CSE 115 Week 12 March 31 – April 4, Announcements March 31 – Exam 8 March 31 – Exam 8 April 6 – Last day to turn in Lab 7 for a max grade of 100%,
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
CS 61C L03 Introduction to C (pt 1) (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Introduction to Computers and Programming Class 21 Arrays Professor Avi Rosenfeld.
7.1 Arrays Introduction to arrays Any array is a collection of objects or primitives Useful when the number of reference variables is large or.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
Data Objects (revisited) Recall that values are stored in data objects, and that each data object holds one value of a particular type. Data objects may.
Tutorial C#. PLAN I. Introduction II. Example of C# program :Hello World III. How to use C# language GUI elements Primitives Types Expressions and operators.
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015 C Tutorial CIS5027.
By – Tanvir Alam.  This tutorial offers several things.  You’ll see some neat features of the language.  You’ll learn the right things to google. 
Introduction to Java University of Sunderland CSE301 Harry R. Erwin, PhD.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
How to Create a Videogame By: Connor McCann. Java Java is one of many programming languages Java is used to run web browsers and most PC video games I.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Game Programming in Java Dr. Jeyakesavan Veerasamy CS faculty, The University of Texas at Dallas Website:
C Functions Pepper. Objectives Create functions Function prototypes Parameters – Pass by value or reference – Sending a reference Return values Math functions.
CS107 References and Arrays By Chris Pable Spring 2009.
CS 61B Data Structures and Programming Methodology July 3, 2008 David Sun.
Java Basics.  To checkout, use: svn co scb07f12/UTORid  Before starting coding always use: svn update.
ArrayList By Neil Butcher. What is the difference between an ArrayList and an Array? An ArrayList is in many ways similar to an array, but has a few subtle.
1 Homework HW5 due today Review a lot of things about allocation of storage that may not have been clear when we covered them in our initial pass Introduction.
1 CS 177 Week 12 Recitation Slides Running Time and Performance.
CS 261 – Recitation 2 Fall 2013 Oregon State University School of Electrical Engineering and Computer Science.
CPSC1301 Computer Science 1 Chapter 8 Introduction to Processing Digital Sounds part 3.
Topic 3: C Basics CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
Java 5 Part 2 CSE301 University of Sunderland Harry Erwin, PhD.
Eclipse Project. Installing Visit to download a copy for your home computerhttp:// –Get Release version 3.0 (or.
Memory Management in Java Computer Science 3 Gerb Objective: Understand references to composite types in Java.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Discussion 7. Make up tutorial Official make up slot: Friday 27 Oct (4-6) (by majority of the people that send me the ) For those who cannot make.
Chapter 6 Methods Chapter 6 - Methods.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
How do you do the following? Find the number of scores within 3 points of the average of 10 scores? What kind of a tool do you need? Today’s notes: Include.
1 ENGI 2420 Structured Programming (Lab Tutorial 7) Memorial University of Newfoundland.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Scis.regis.edu ● CS-362: Data Structures Week 6 Part 2 Dr. Jesús Borrego 1.
PROGRAMMING 1 – HELPER INSTRUCTIONS ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED BY NANCY M. AMATO AND JORY DENNY 1.
Memory Management in Java Mr. Gerb Computer Science 4.
Pointers and Classes.
Intro to ETEC Java.
Lecture Notes – Week 3 Lecture-2
Announcements & review
John D. McGregor Module 0 Session 2 Infrastructure and problem
From C++ to Java Java history: Oak, toaster-ovens, internet language, panacea What it is O-O language, not a hybrid (cf. C++) compiled to byte-code, executed.
Lecture 7: Introduction to Processing
2 code samples int [] array; int i, j, temp; for(i = 0; i < array.length/2; i++) { j = array.length-1-i; temp = array[i]; array[i] = array[j]; array[j]
C Programming Pointers
Compile and run c files.
Tic-Tac-Toe Game Engine
Two dimensional arrays.
SPL – PS1 Introduction to C++.
Introduction to C CS 3410.
Presentation transcript:

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

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

C versus Java Local variables have to be at the top Local variables have to be at the top No Boolean type No Boolean type Structures Structures /* … */ /* … */ printf(“Foo is %d and bar is %f\n”, 5, 3.5); printf(“Foo is %d and bar is %f\n”, 5, 3.5); for loops syntax for loops syntax variables aren’t initialized to anything variables aren’t initialized to anything anywhere Classes /*... */ or // System.out.print

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

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

Pointers (cont’d) Use the & operator to get the address of a variable. Use the & operator to get the address of a variable. x = &y;5 yx *x = 7;7 yx Use the * operator to dereference a pointer. Use the * operator to dereference a pointer.

GamesCrafters Download the gamesman package for Unix. As of right now, there is no version for Windows. research/gametheory/current Download the gamesman package for Unix. As of right now, there is no version for Windows. research/gametheory/current research/gametheory/current research/gametheory/current The GamesCrafters website has the 10- step tutorial for writing a game module. The GamesCrafters website has the 10- step tutorial for writing a game module. software/gamesman software/gamesman

Hash Functions A hash function takes your board position and converts it into a number. 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. 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. You’ll need a hash function and an unhash function, which will take a number and give you the board position.

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

The Makefile There are 4 places where you need to add your game. 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. 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.

The Makefile: change #1 TTT_EXE= $(BINDIR)/mttt TTT_EXE= $(BINDIR)/mttt TTT_OBJ= mttt.o TTT_SO = $(LIBDIR)/libmttt.so

The Makefile: change #2 text_all: ${1210_EXE} ${TTT_EXE}... text_all: ${1210_EXE} ${TTT_EXE}... so_all: ${1210_SO} ${TTT_SO}... so_all: ${1210_SO} ${TTT_SO}...

The Makefile: change #3 ${TTT_OBJ} :${SOLVER_INCLUDE} ${TTT_OBJ} :${SOLVER_INCLUDE} ${TTT_EXE}:${TTT_OBJ}... ${TTT_SO}:${TTT_OBJ}...

The Makefile: change #4 At the very end of the makefile... At the very end of the makefile...clean: rm –f ${1210_EXE} ${1210_OBJ}... minimal: rm –f ${1210_OBJ} ${TTT_OBJ}...

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

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

Questions?