Need help with Othello Program Project AI and capturing

Help With Othello C++ project, Caputuring a move with AI

Page 1 of 1

5 Replies - 2104 Views - Last Post: 02 May 2010 - 01:49 PM Rate Topic: -----

#1 codefreak85  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-May 10

Need help with Othello Program Project AI and capturing

Posted 02 May 2010 - 10:05 AM

Hello coders,


I have a project due in three days and was wondering if any one can point me in the right direction on this one. Thier are 5 parts to the porject and im in the last part, part 5. Part 5 ask the progamer to write a the main code for this program where the code looks for advailbe peice and make sure the user imputs the correct move and then captures a peice. My code is below, please any help would be great appricated. But let me make it clear, I dont want you to finish the code just to shoot in the right direction. I have been at it for a couple days now and everytime I think I going in the right direction I get overwhlemd and it feels like my brain is going to explode!



// Initialize Board
void init(char board[BOARD_SIZE][BOARD_SIZE])
{
	for (int row = 0; row < BOARD_SIZE; ++row)
	{
		for (int col = 0; col < BOARD_SIZE; ++col)
		{
			board[3][3] = 'O';
			board[4][4] = 'O';
			board[3][4] = '@';
			board[4][3] = '@';
			board[row][col] = ' ';
		}
	}
}





// Print BORAD	8 by 8
void draw(char board[BOARD_SIZE][BOARD_SIZE])
{
	std::cout << "  ABCDEFGH\n"
			  << " +--------+\n";	

	for (int row = 0; row < BOARD_SIZE; ++row)
	{
		std::cout << row + 1  << "|";

		for (int col = 0; col < BOARD_SIZE; ++col)
		{	
			std::cout << board[row][col];
		}

		std::cout << "|\n";
	}

	std::cout << " +--------+\n"
			  << "  ABCDEFGH\n";	

	std::cout << std::endl;
}

// this is the part im haveing trouble with.
// Call is valid poston at north
int is_valid_position_at_in_NORTH_direction(char board[BOARD_SIZE][BOARD_SIZE], int row, int col, int x)
{
	int space = 0;

	if (board[row][col + 1] == ' ')
	{
		std::cout << space;
		return space;
	
	}
		
	
}






// Call is valid poston at N, S, E, W, NE,SE, NW, SW
void is_valid_position_at(char board[BOARD_SIZE][BOARD_SIZE], int row, int col, int x)
{
	
	is_valid_position_at_in_NORTH_direction(board, row, col, x);
	
}









//Is available function to check the enrtry
void is_available(char board[BOARD_SIZE][BOARD_SIZE], int row, int col, int x)
{
	char turn[100];

	while (1)
	{
		std::cout << "Invalid position\n";

		if (x != 1)
		{
			std::cout << "WHITE's turn: ";
			std::cin >> turn;
			std::cout << std::endl;
		}

		else 
		{
			std::cout << "BLACK's turn: ";
			std::cin >> turn; 
			std::cout << std::endl;
		}
		
		switch (turn[0])
		{
			case 'A': col = 0; break;
			case 'B': col = 1; break;
			case 'C': col = 2; break;
			case 'D': col = 3; break;
			case 'E': col = 4; break;
			case 'F': col = 5; break;
			case 'G': col = 6; break;
			case 'H': col = 7; break;
		}
		
		switch (turn[1])
		{
			case '1': row = 0; break;
			case '2': row = 1; break;
			case '3': row = 2; break;
			case '4': row = 3; break;
			case '5': row = 4; break;
			case '6': row = 5; break;
			case '7': row = 6; break;
			case '8': row = 7; break;
		}
		
		//Black print
		if (x == 1)
		{
			board[row][col] = '@';
		}
	
		//White print
		else 
		{
			board[row][col] = 'O';
		}
		
		draw(board);
				
		break;
	}
}








//fuction: option play a game
void play()
{
	//Set Char users Option 
	char turn[100];
	char board[BOARD_SIZE][BOARD_SIZE];
	int x = 0, z = 0, row, col;
	
	init(board);
	draw(board);

	while (1)
	{
		if (x == 1)
		{
			std::cout << "WHITE's turn: ";
			std::cin >> turn;
			std::cout << std::endl;
			x =- 1;
		}

		else 
		{
			std::cout << "BLACK's turn: ";
			std::cin >> turn; 
			std::cout << std::endl;
			x =+ 1;
		}
	
		if (turn[0] == 'q')
		{	
			break;
		}
		
		switch (turn[0])
		{
			case 'A': col = 0; break;
			case 'B': col = 1; break;
			case 'C': col = 2; break;
			case 'D': col = 3; break;
			case 'E': col = 4; break;
			case 'F': col = 5; break;
			case 'G': col = 6; break;
			case 'H': col = 7; break;
		}
		
		switch (turn[1])
		{
			case '1': row = 0; break;
			case '2': row = 1; break;
			case '3': row = 2; break;
			case '4': row = 3; break;
			case '5': row = 4; break;
			case '6': row = 5; break;
			case '7': row = 6; break;
			case '8': row = 7; break;
		}
		
	
		is_valid_position_at(board, row, col, x);

		if (board[row][col] != ' ') 
		{
			is_available(board, row, col, x);
		}
		 
		else 
		{
			//Black print
			if (x == 1)
			{
				board[row][col] = '@';
			}
	
			//White print
			else 
			{
				board[row][col] = 'O';
			}
		
			draw(board);
		}
	}
		
}







//INT MAIN
int main()
{
	//Set Char users Option 
	char option = ' ';

	option = 'x';

	//WHILE loop to have options loop for user
	while(option != 'Q' || option != 'q')
	{
		//Options:
		std::cout << "Welcome to Super Othello Version 0.1\n"
				  << "by Joseph Miller\n\n"
			      << "[?] Help\n"
			      << "[P/p] Play a new game\n"
			      << "[L/l] Load a previous game\n"
			      << "[S/s] Setup the board\n"
			      << "[Q/q] Quit\n"
			      << "\nEnter option: ";

		//Have user enter their choice option
		std::cin >> option;
	
		std::cout << std::endl;
		
		switch (option)
		{
			case '?' : help(); break;
		
			case 'P' :
			case 'p' : play(); break;
		
			case 'L' :
			case 'l' : load_game(); break;

			case 'S' :
			case 's' : setup(); break;
			
			case 'Q' :
			case 'q' : 
			{	
				std::cout << "Thanks for playing Super Othello Version 0.1\n";
			    break;
			}
		}
	
		std::cout << std::endl;
	}

	return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Need help with Othello Program Project AI and capturing

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2934
  • View blog
  • Posts: 10,142
  • Joined: 08-August 08

Re: Need help with Othello Program Project AI and capturing

Posted 02 May 2010 - 11:44 AM

What part isn't working as you would like? As you've posted it, we would need to create a new project, run it, determine what isn't happening that should, and then debug it for you. That's not what we're here for. You need to break it down a little and show us where you're having a problem.
Was This Post Helpful? 0
  • +
  • -

#3 codefreak85  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-May 10

Re: Need help with Othello Program Project AI and capturing

Posted 02 May 2010 - 11:50 AM

Hello,


The code you have it just a tiny bit of the intire projects. I dont know why everyone jumps to conclustion so fast on this website thinking everyone wants them to due their work. It complies and runs fine. I ask just for the help with the captureing a peice and scaing through an array then return with the row or col change to the peice that was capture. I need help with that presdeocode. Thanks
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2934
  • View blog
  • Posts: 10,142
  • Joined: 08-August 08

Re: Need help with Othello Program Project AI and capturing

Posted 02 May 2010 - 12:13 PM

Well, if you're checking the user's move you need to check to see that there is at least one row, column, or diagonal consisting of opposite colored piece(s) and where there is a like colored piece at the end. Then you need to "flip" those row/column/diagonals. I'd start by creating functions to examine/flip rows and columns. Then diagonals should be easy.

This post has been edited by CTphpnwb: 02 May 2010 - 12:13 PM

Was This Post Helpful? 0
  • +
  • -

#5 codefreak85  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-May 10

Re: Need help with Othello Program Project AI and capturing

Posted 02 May 2010 - 01:30 PM

Thanks,

Ill try it out.

I created a funtion on top of anthore funtion, and return if it was true or not. The only problem I have right now, is that I have many if statments, and the if statment is fixed with the postion it surrounds it self with. What I need is a for statment what allows me to just fixed that eniter row or col. I think I need to scan the row and col. What would you say?
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2934
  • View blog
  • Posts: 10,142
  • Joined: 08-August 08

Re: Need help with Othello Program Project AI and capturing

Posted 02 May 2010 - 01:49 PM

This is off the top of my head and untested:

bool function checkrow_rightside()
{
	goodrow = false;
	possiblygood = false;
	for(xpos = playerx+1; xpos < BOARD_SIZE; xpos++)
	{
		if(board[xpos][playery] == opponent_piece)
		{
			possiblygood = true;
			// keep testing
		} else if(board[xpos][playery] == mypiece && possiblygood)
		{
			goodrow = true;
			break;
		} else if(board[xpos][playery] == emptyspace)
		{
			break;
		}
	}
		return goodrow;
}

This post has been edited by CTphpnwb: 02 May 2010 - 01:50 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1