#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct game_piece
{
};
struct game_board
{
};
void game_piece_init_default(struct game_piece* piece)
{
}
void game_piece_init(struct game_piece* piece, char* new_label)
{
}
char* game_piece_get_label(struct game_piece* piece)
{
return "";
}
char* game_piece_to_string(struct game_piece* piece)
{
return "";
}
void game_board_init(struct game_board* game_board, int rows, int cols)
{
}
int game_board_is_space_valid(struct game_board* game_board, int row, int
col)
{
return 0;
}
int game_board_add_piece(struct game_board* game_board, struct game_piece*
piece, int row, int col)
{
return 0;
}
int game_board_move_piece(struct game_board* game_board, int src_row, int
src_col, int dest_row, int dest_col)
{
return 0;
}
void game_board_print(struct game_board* game_board)
{
}
int main()
{
/* declare local variables */
int row;
int col;
int destRow;
int destCol;
int rowNum;
int colNum;
struct game_board board;
struct game_piece piece;
char input_string[30];
/* get the size of the game board */
printf("Please enter the number of rows.\n");
scanf("%d", &rowNum);
printf("Please enter the number of columns.\n");
scanf("%d", &colNum);
game_board_init(&board, rowNum, colNum);
/* get the first piece's label */
printf("Please enter a label for a new piece. Enter \"Q\" when
done.\n");
scanf("%s", input_string);
while (strcmp(input_string, "Q") != 0 && strcmp(input_string, "q") !=
0)
{
game_piece_init(&piece, input_string);
/* get the location to place the piece */
printf("Please enter a row for the piece.\n");
scanf("%d", &row);
printf("Please enter a column for the piece.\n");
scanf("%d", &col);
/* verify the space is valid then add the piece to the board */
if (game_board_is_space_valid(&board, row, col))
{
if (game_board_add_piece(&board, &piece, row, col))
{
printf("New piece \"%s\" added.\n",
game_piece_get_label(&piece));
}
else
{
printf("A piece is already at that space.\n");
}
}
else
{
printf("Invalid row and/or column.\n");
}
/* get the label for the next piece */
printf("Please enter a label for a new piece. Enter \"Q\" when
done.");
scanf("%s", input_string);
}
/* print the board and check if user wants to move a piece */
game_board_print(&board);
printf("Would you like to move a piece? Enter \"Y\" to move a
piece.\n");
scanf("%s", input_string);
while (strcmp(input_string, "Y") == 0 || strcmp(input_string, "y") ==
0)
{
/* get the location of the piece */
printf("Please enter the piece's row.");
scanf("%d", &row);
printf("Please enter the piece's column.");
scanf("%d", &col);
/* get the destination for the piece */
printf("Please enter the piece's new row.");
scanf("%d", &destRow);
printf("Please enter the piece's new column.");
scanf("%d", &destCol);
/* verify both spaces are valid then move the piece */
if (game_board_is_space_valid(&board, row, col) &&
game_board_is_space_valid(&board, destRow, destCol))
{
if (game_board_move_piece(&board, row, col, destRow, destCol))
{
printf("Piece moved to new space.\n");
}
else
{
printf("A piece is already in that space.\n");
}
}
else
{
printf("A row or column is invalid. No piece moved.\n");
}
/* print the board and check if the user wants move another piece
*/
game_board_print(&board);
printf("Would you like to move a piece? Enter \"Y\" to move a
piece.\n");
scanf("%s", input_string);
}
return 0;
}
IN LANGUAGE C
//Here is your answer..
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct game_piece
{
char lable[30];
};
struct game_board
{
struct game_piece* board[50][50];
int rows;
int columns;
};
void game_piece_init_default(struct game_piece* piece)
{
piece= (struct game_piece*)malloc(sizeof(struct game_piece));
// strcpy(piece->lable,"---");
piece->lable[0]='-';
piece->lable[1]='-';
piece->lable[2]='-';
piece->lable[3]='\0';
}
void game_piece_init(struct game_piece* piece, char*
new_label)
{
strcpy(piece->lable,new_label);
}
char* game_piece_get_label(struct game_piece* piece)
{
return piece->lable;
}
char* game_piece_to_string(struct game_piece* piece)
{
char* str=(char*)malloc(sizeof(char)*4);
str[0]=' ';
str[1]=' ';
str[2]=' ';
str[3]='\0';
int len=strlen(piece->lable);
printf("%d",len);
int i;
if(len<=3)
{
for(i=0;i<len;i++)
str[i]=piece->lable[i];
}
else
{
for(i=0;i<3;i++)
str[i]=piece->lable[i];
}
return str;
}
void game_board_init(struct game_board* game_board, int rows,
int cols)
{
int i,j;
game_board->rows=rows;
game_board->columns=cols;
for(i=0;i<rows;i++)
{
for( j=0;j<cols;j++)
{
game_piece_init_default(game_board->board[i][j]);
}
}
}
int game_board_is_space_valid(struct game_board* game_board, int
row, int col)
{
if(row<0 || col<0 || row>game_board->rows || col>
game_board->columns)
return 0;
return 1;
}
int game_board_add_piece(struct game_board* game_board, struct
game_piece* piece, int row, int col)
{
if(game_board_is_space_valid(game_board,row,col) &&
strcasecmp(
game_board->board[row][col]->lable,"---")==1)
{
game_board->board[row][col]=piece;
return 1;
}
return 0;
}
int game_board_move_piece(struct game_board* game_board, int
src_row, int src_col, int dest_row, int dest_col)
{
if(game_board_is_space_valid(game_board,src_row,src_col) &&
game_board_is_space_valid(game_board,dest_row,dest_col)&&
strcasecmp(
game_board->board[dest_row][dest_col]->lable,"---")==0)
{
struct game_piece*
temp=game_board->board[dest_row][dest_col];
game_board->board[dest_row][dest_col]=game_board->board[src_row][src_col];
game_board->board[src_row][src_col]=temp;
return 1;
}
return 0;
}
void game_board_print(struct game_board* game_board)
{
int i,j;
printf("The GameBoard\n");
printf("------------------------------------------------\n");
for(i=0;i<game_board->rows;i++)
{
for( j=0;j<game_board->columns;j++)
{
printf("%s ",game_piece_to_string(game_board->board[i][j]));
}
printf("\n");
}
}
int main()
{
/* declare local variables */
int row;
int col;
int destRow;
int destCol;
int rowNum;
int colNum;
struct game_board board;
struct game_piece piece;
char input_string[30];
/* get the size of the game board */
printf("Please enter the number of rows.\n");
scanf("%d", &rowNum);
printf("Please enter the number of columns.\n");
scanf("%d", &colNum);
game_board_init(&board, rowNum, colNum);
/* get the first piece's label */
printf("Please enter a label for a new piece. Enter \"Q\" when done.\n");
scanf("%s", input_string);
while (strcmp(input_string, "Q") != 0 &&
strcmp(input_string, "q") !=0)
{
game_piece_init(&piece, input_string);
/* get the location to place the piece */
printf("Please enter a row for the piece.\n");
scanf("%d", &row);
printf("Please enter a column for the piece.\n");
scanf("%d", &col);
/* verify the space is valid then add the piece to the board */
if (game_board_is_space_valid(&board, row, col))
{
if (game_board_add_piece(&board, &piece, row,
col))
{
printf("New piece \"%s\" added.\n",
game_piece_get_label(&piece));
}
else
{
printf("A piece is already at that space.\n");
}
}
else
{
printf("Invalid row and/or column.\n");
}
/* get the label for the next piece */
printf("Please enter a label for a new piece. Enter \"Q\" when done.");
scanf("%s", input_string);
}
/* print the board and check if user wants to move a piece */
game_board_print(&board);
printf("Would you like to move a piece? Enter \"Y\" to move a piece.\n");
scanf("%s", input_string);
while (strcmp(input_string, "Y") == 0 || strcmp(input_string, "y") ==
0)
{
/* get the location of the piece */
printf("Please enter the piece's row.");
scanf("%d", &row);
printf("Please enter the piece's column.");
scanf("%d", &col);
/* get the destination for the piece */
printf("Please enter the piece's new row.");
scanf("%d", &destRow);
printf("Please enter the piece's new column.");
scanf("%d", &destCol);
/* verify both spaces are valid then move the piece */
if (game_board_is_space_valid(&board, row, col) &&
game_board_is_space_valid(&board, destRow, destCol))
{
if (game_board_move_piece(&board, row, col, destRow,
destCol))
{
printf("Piece moved to new space.\n");
}
else
{
printf("A piece is already in that space.\n");
}
}
else
{
printf("A row or column is invalid. No piece moved.\n");
}
/* print the board and check if the user wants move another piece
*/
game_board_print(&board);
printf("Would you like to move a piece? Enter \"Y\" to move a piece.\n");
scanf("%s", input_string);
}
return 0;
}
#include <stdio.h> #include <stdlib.h> #include <string.h> struct game_piece { ...
IrmaMoves.h : #include "IrmaMoves.h" typedef struct Move { Irma irma; // an instance of Irma L Location from_loc; // location where Irma is moving from Location current_loc; // location where Irma is passing over Location to_loc; // location where Irma is moving to } Move; typedef struct Location { char col; // the square's column ('a' through 'h') int row; // the square's row (0 through 7) } Location; typedef struct Irma { int ws; // wind speed (MPH) int...
Can someone tell me why this is not printing in the screen. I know i commented out the first couple functions but the last one is not working. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <stdlib.h> #include <time.h> #define ROWS 5 #define COLS 5 #define FREE 2 #define SCALE 15 #define SHIFT 1 #define MAXVAL 75 #define FALSE 0 #define TRUE 1 void welcomeScreen(); void clearScreen(); void displayExplicitCard(); void displayCard(); void displayRandomCard(); void fillCardRand(); void setValue(); void displayBingoCard(); void initializeArrays (); int main...
Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner method, it declares a winner for horizontal wins, but not for vertical. if anyone can see what im doing wrong. public class ConnectFour { /** Number of columns on the board. */ public static final int COLUMNS = 7; /** Number of rows on the board. */ public static final int ROWS = 6; /** Character for computer player's pieces */ public static final...
C program help 2. For the following code: #include "stdafx.h" struct State char out struct State *next[2]; b; typedef struct State States; #define STe &FSM[8] #define ST1 &FSM[1] #define ST2 &FSM[2] States FSM[3] { {"L', {STe, ST1)), {'1', {STe, sT2)), {ST1, = {.2', ST2))); int main() States "ptr &FSM[e]; int in; while (1) printf("cIn", ptr->out); printf("Enter a e or 1 to operate this machine: "); scanf s("Xd", &in); ptr ptr->next[in]; return e; Draw the finite state machine diagram for this...
c++ help please! Create a 2D character array in your main function and use nested for loops to fill the array with the letter ‘e’ to represent empty spaces. Create a function to print the board on the screen using a nested for loop. The function header is: void printBoard (char board [][3]) Create a function that checks whether a particular space has already been filled. If the space is filled it returns a boolean value of true, otherwise false....
This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you. public class Cell { // Displays 'B' for the black disk player. public static final char BLACK = 'B'; // Displays 'W' for the white disk player. public static final char WHITE = 'W'; // Displays '*' for the possible moves available. public static...
I need a basic program in C to modify my program with the following instructions: Create a program in C that will: Add an option 4 to your menu for "Play Bingo" -read in a bingo call (e,g, B6, I17, G57, G65) -checks to see if the bingo call read in is valid (i.e., G65 is not valid) -marks all the boards that have the bingo call -checks to see if there is a winner, for our purposes winning means...
Can somebody help me with this coding the program allow 2 players play tic Tac Toe. however, mine does not take a turn. after player 1 input the tow and column the program eliminated. I want this program run until find a winner. also can somebody add function 1 player vs computer mode as well? Thanks! >>>>>>>>>>>>>Main program >>>>>>>>>>>>>>>>>>>>>>> #include "myheader.h" int main() { const int NUM_ROWS = 3; const int NUM_COLS = 3; // Variables bool again; bool won;...
Tic Tac Toe Game: Help, please. Design and implement a console based Tic Tac Toe game. The objective of this project is to demonstrate your understanding of various programming concepts including Object Oriented Programming (OOP) and design. Tic Tac Toe is a two player game. In your implementation one opponent will be a human player and the other a computer player. ? The game is played on a 3 x 3 game board. ? The first player is known as...