Sponsored Content
Top Forums Programming Two player game, forking & sockets Post 302528177 by Shang on Tuesday 7th of June 2011 02:41:28 PM
Old 06-07-2011
Thanks! Now I think that would give me some kickoff. I'll be back if any question arises.

---------- Post updated 07-06-11 at 08:41 PM ---------- Previous update was 06-06-11 at 09:06 PM ----------

As promised, I am back with questions Smilie I have read about different approaches and decided to use SysV shared memory for a start.
First problem:
Assuming that we don't know how many clients(c) will connect and how many games(floor(c/2)) will be started the question is how to manage this shared memory segment?
My first idea was to create an array of pointers to game_state (type, see below), which would be the argument for shmat() function and store information about all games.
But how to dynamically expand this array in case of new game start without ruining attachment? I mean that when we malloc new, bigger amount of memory and freeing old one, the addresses changes. To be honest I have feelings that this idea is useless.
Code:
typedef struct {
    int player_ids[GCOUNT];    // array with player ids
    char board[BOARD_SIZE][BOARD_SIZE];    // 10x10 game board
    char moves_sequence[TILES_NUM];    // array containing information who did what move
    player_stat player_stats[GCOUNT];        // point to a structure containing information who has how many points
} game_state;

Second problem:
How to implement reading and modification of shared memory segment in turns? (player1-mainprocess-player2-mainprocess-player1-mainprocess-player2-....)
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Association b/w sockets & processes

Hi, Is there any way i can know the association between sockets and the processes which created them. :confused: (5 Replies)
Discussion started by: soorajmu
5 Replies

2. Linux

Having player problem && need your help.

My System is FC3, The following Players don't run well: 1).Helix Player couldn't play MP3 and *.wma files, 2).Totem is the same, 3)XMMS couldn't play .wma files. I am a newer of Linux,but I like Linux,just as you. Could you help me? Thank you! (1 Reply)
Discussion started by: letcorpmuv
1 Replies

3. Programming

Forking in a loop

When I compile this C programme I get different outputs each time I run it Please explain to me whats happening in the code if you can give me a detailed explanation. Because I am stuck with this. #include <stdio.h> main(){ int i = 0; printf("I am the... (1 Reply)
Discussion started by: manjuWicky
1 Replies

4. UNIX for Advanced & Expert Users

Forking

When I compile this C programme I get different outputs each time I run it Please explain to me whats happening in the code if you can give me a detailed explanation with the schedular functionality it will help a lot. Because I am stuck with this. #include <stdio.h> main(){... (3 Replies)
Discussion started by: manjuWicky
3 Replies

5. HP-UX

Mozilla & Macromedia Flash Player Plugin Problem

Hello All, I am using Mozilla 1.7.8 on hp-ux 11.00, and install flash player 6 for it. it is giving following errors and get crashed. when i want to open a site need flash plugin. Gtk-WARNING **: invalid cast from `GtkSuperWin' to `GtkWidget' Gtk-WARNING **: invalid cast from `GtkSuperWin'... (1 Reply)
Discussion started by: Awadhesh
1 Replies

6. Programming

forking within a thread

Is it safe to call fork+exec in a multithreaded application. Because In my multithreaded application, I need to execute another program in each thread. I am using solaris 10. Any suggestions pls. (2 Replies)
Discussion started by: axes
2 Replies

7. Programming

need help in forking

I have an input file with contents like: 5785690|68690|898809 7960789|89709|789789 7669900|87865|659708 7869098|65769|347658 so on.. I need to pass this file to 10 parallely running processes (forking)so that each line is processed by a process and no line is processed twice and write the... (1 Reply)
Discussion started by: rkrish
1 Replies

8. Linux

Unable to install VLC media player or any other player in SL 6.3 distro

Hi, I am unable to install VLC or any other media players in my SL 6.3 distro. I am using yum utility to install the packages, but i am getting the below error messages, --> Processing Dependency: libpng15.so.15()(64bit) for package: vlc-core-2.0.3-1.fc18.x86_64 --> Processing... (1 Reply)
Discussion started by: vel4ever
1 Replies
GRIDLOCK(6)							   Games Manual 						       GRIDLOCK(6)

NAME
Gridlock - collection of grid-based board games SYNOPSIS
Gridlock DESCRIPTION
This manual page documents briefly the Gridlock command. Gridlock is a collection of several grid-based strategy games. The games include Ataxx, Reversi, Gomoku, Connect Four, Breakthrough, Glass Bead, Hexapawn, Quad Wrangle, Cats and Dogs and Moray Eels. After launching the application, the game window will appear. Select the game you want to play from the "Game" popup menu in the upper right. Some games have different starting configurations (board size, grid layout, etc); when one of those games are selected a "Configura- tions" popup menu will appear from which you can select a configuration. The bottom right displays the color and status of the two players. Each player's color is shown by a circle; the player whose turn it is has a filled circle. For games in which players have a score (Ataxx, Eeversi, Glass Bead), the scores are shown next to the player labels. Popup windows underneath each player's label allow you to specify whether each player is human or computer-controlled, and the difficulty of computer players. (Note that "Hard" computer opponents may take a long time to make their moves). The rest of the window contains the game board. To make a move, click on the cell where you wish to place a piece. Ataxx and Breakthrough require that you move from one cell to another; to do this first click on the cell you wish to move from, then click on the cell you wish to move to. For all games, cells that are legal moves will become highlighted when you move the mouse over them. If you are unable to make a move, you can pass by clicking the "Pass" button on the right. The "Restart" button will restart the game, requiring confirmation if a game is in progress. You can play these games over the network. It is possible to save and load games. SEE ALSO
GNUstep(7). AUTHOR
This manual page was written and updated by Gurkan Sengun <gurkan@linuks.mine.nu>, for the Debian GNU/Linux system (but may be used by oth- ers). October 17, 2003 GRIDLOCK(6)
All times are GMT -4. The time now is 04:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy