Sponsored Content
Full Discussion: C++ Help
Top Forums Programming C++ Help Post 302274434 by RossMc on Wednesday 7th of January 2009 02:43:38 PM
Old 01-07-2009
Quote:
Originally Posted by Corona688
You're putting X-es into the array for player one, how about using 1's and 2's instead? That'll make it easier to keep track of the players.

I would declare a variable outside the loop to keep track of whose turn it is, and toggle it back and forth at the top of the loop. Here's a really bare skeleton of the idea:
Code:
int player=2;

while(! gameover)
{
  int value;

  if(player == 1)
  {
    player=2;
  }
  else 
  {
    player=1;
  }

  cout << "Player " << player << "'s turn:" << endl;
  cin >> value;
  board[value]=player;

  check_if_game_over;
}

cout << "Player " << player << " wins!" << endl;

So that would go before

Code:
cout << "Player 1 Your Turn Please Enter Which Cell You Would Like" << endl;
 
cin >> row >> column;
}
 
if(board[row-1][column-1] ==' ')
 
board[row-1][column-1] = 'X'; }

Or instead of?
 
DAB(6)								 BSD Games Manual							    DAB(6)

NAME
dab -- Dots and Boxes game SYNOPSIS
dab [-aw] [-n ngames] [-p <c|h><c|h>] [xdim [ydim]] DESCRIPTION
dab is a game where each player tries to complete the most boxes. A turn consists of putting one border of a box; the player setting the fourth and final border of a box gets the point for the box and has another turn. The keys used are the vi keys: k for up, j for down, h for left, and l for right. To switch between even and odd rows, use one of the fol- lowing keys: u (diagonal right up), y (diagonal left up), b (diagonal left down), n (diagonal right down); <space> sets a new border, CTRL-L and CTRL-R redraw the screen, and q quits the game. Support options are: -a Don't use the alternate character set. -n ngames ngames games will be played. (Especially useful in -p cc mode.) -p <c|h><c|h> Select which of the two players is a human or a computer. The first argument is the first player; c stands for computer and h for human. -w Wait for a character press between games. xdim and ydim define the size of the board in the x and y dimensions. AUTHORS
Christos Zoulas <christos@NetBSD.org> SEE ALSO
Elwyn R. Berlekamp, The Dots and Boxes Game: Sophisticated Child's Play, A K Peters, 2000, http://www.akpeters.com/book.asp?bID=111. BSD
December 24, 2003 BSD
All times are GMT -4. The time now is 05:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy