Help making a game

This is a discussion on Help making a game within the Game Programming forums, part of the General Programming Boards category; I'm fairly new to C and I need help creating the game of GO. My first problem is drawing the ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    4

    Help making a game

    I'm fairly new to C and I need help creating the game of GO. My first problem is drawing the board. I need a board that is 19x19 spaces with the rows and columns labeled 1-19. I have already assigned a char [19][19] to allow for all my spaces but cannot get the rows labeled. Any help with this would be appreciated. Thanks

  2. #2
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    Here is what I have so far:

    Code:
    #include "stdafx.h"
    #include "stdio.h"
    #include "stdlib.h"
    #include "process.h"
    #include "windows.h"  // for System() call
    
    
    
    #define TRUE  1
    #define FALSE 0
    
    char BoardSize [19][19];
    
    int DrawBoard(int i, int j);
    
    int _tmain()
    {
    	
    	int DrawBoard;
    	return 0;
    }
    
    int DrawBoard (int i, int j)
    {
    // Here we draw the board
    
    	printf("\n\n       \n\n");
    	printf("          Welcome to the Game of GO!!\n\n");
    	printf(" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\n");
    	for ( int i = 0; i < BoardSize; i++ )
    		{
    			
    			printf(" %2d ", (i + 1)); // Row Header
    			for (int j=0; j < BoardSize; j++);
    	}

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Boardsize is an array, and the name of the array refers to the first element in that array. so i < Boardsize is comparing i to whatever the value of boardsize[0][0], might be.

    I would use a define:

    Code:
    #define SIZE 19
    
    //then use
    
    for(row = 0; row < SIZE; row++) {
      printf("\n%3d ", row+1);         //row numbers
      for(col = 0; col < SIZE; col++) {
        //etc.
      }
    }
    Good luck with Go!

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    Quote Originally Posted by Adak View Post
    Boardsize is an array, and the name of the array refers to the first element in that array. so i < Boardsize is comparing i to whatever the value of boardsize[0][0], might be.
    Not quite, it refers to the address of the first element in the array. i < Boardsize is comparing the value in i to whatever the address of Boardsize[0][0] is.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409

    .

    admire your ambition, pass n play should b do-able wit both players agreeing state of play and life/death status of stones as in real game. AI is notoriously hard to model for Go though, due to many nuances.. chess becomes simpler as play progresses, in go it is the opposite.!

  6. #6
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    Still having problems with this code. I need to use an array or else it will not fill in all the blanks in the table, just the first column. right now I am having a problem with it saying that "j" is an undeclared identifier and I cannot figure out how to fix it. Please help out.

    Code:
    // Go Board.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include "stdio.h"
    #include "stdlib.h"
    #include "process.h"
    #include "windows.h"  
    
    #define BLACK_STONE  '*'
    #define WHITE_STONE	 '0'
    #define EMPTY		 ' '
    
    #define BoardSize 19
    
    void MakePlay (int i[19],int j[19]);
    
    
    int main()
    {
    	
    	printf("\n\n       \n\n");
    	printf("          Welcome to the Game of GO!!\n\n");
    	printf(" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\n");
    	for ( int i = 0; i < BoardSize; i++ )
    
    	{	
    			printf(" %2d ", (i + 1)); // Row Header
    				for (int j=0; j < BoardSize; j++);
    				{
    					MakePlay (i,j);
    				}
    				printf("\n");
    			}
    
    
    	return 0;
    }
    
    {
    	MakePlay(int i[19], int j[19])
    
    		printf("%c", BLACK_STONE);
    }

  7. #7
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    The first thing you should do is DECIDE if you are going to write this in C or C++.

  8. #8
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    We have a game programming forum. Moved to game programming.

  9. #9
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    Well the class is for c programming but I am using a C++ compiler. I am very new to C and do not know the differences between c and c++. Also I am not too familiar with arrays and that is what the teacher wants us to do. Any help would be appreciated and thanks for moving it to the correct forum.

  10. #10
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409
    your compiler will most likely work with c or c++ projects, the problem you are probably having is that you selected a 'c source language' project, but your code contains elements of c++ that will not compile in a C console project, like declaring integers local to your for loop

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    In your compiler options, you should have a choice of what you want the default compilers to be. Choose .c for C, and .cpp for C++.

    Couldn't interest you in something simpler, could I? Connect 4 is a strategy game for two that many universities use for competition in programming classes.

    Unfortunately, there aren't that many GO players in English speaking forums.

  12. #12
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Code:
    				for (int j=0; j < BoardSize; j++);
    				{
    					MakePlay (i,j);
    				}
    The semicolon I've indicated in red will make the code do really bad things. In essence it's the entire body of the for loop, and the curly braces that follow are a random block that you've introduced. So what will happen is that the for loop will execute as you programmed it to, do nothing each time, and then the code in the block will execute once (with j == BoardSize, which will probably crash it!). Or it would if j existed outside of the loop; since it doesn't, you're getting that error message. The short of it is that you should get rid of that semicolon.

    You're also trying to pass a single integer as an array of ints to your MakePlay function. That's not going to work. Maybe you could start by looking at some code like this:
    Code:
    /* This is C, not C++. */
    
    #include <stdio.h>
    
    #define WIDTH 40
    #define HEIGHT 20
    
    /** When you pass an array to a function, you must specify all but the leftmost
        dimension.
    */
    void init_board(char board[][HEIGHT]);
    
    void print_board(char board[][HEIGHT]);
    
    int main() {
        char board[WIDTH][HEIGHT];
        
        init_board(board);
        
        print_board(board);
        
        return 0;
    }
    
    void init_board(char board[][HEIGHT]) {
        int x, y;  /* declaring variables inside for loops isn't C89 */
        for(y = 0; y < HEIGHT; y ++) {
            for(x = 0; x < WIDTH; x ++) {
                board[x][y] = '-';
            }
        }
    }
    
    void print_board(char board[][HEIGHT]) {
        int x, y;  /* declaring variables inside for loops isn't C89 */
        for(y = 0; y < HEIGHT; y ++) {
            for(x = 0; x < WIDTH; x ++) {
                printf("%c", board[x][y]);
            }
            printf("\n");
        }
    }
    That's just some code I whipped up that doesn't do anything very interesting, but it at least shows you the syntax for passing arrays to functions and accessing array indices.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Event driven game engine
    By abachler in forum Game Programming
    Replies: 9
    Last Post: 12-01-2009, 05:03 AM
  2. PC Game project requires c++ programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-21-2006, 11:23 PM
  3. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM
  4. Someone help me with this game??
    By stehigs321 in forum Game Programming
    Replies: 15
    Last Post: 10-30-2003, 08:42 PM
  5. Lets Play Money Making Game
    By ggs in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-04-2001, 08:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21