Exemplo n.º 1
0
void main(void)
{
	Stack<int> stack;

	stack.PushBack(1);
	stack.PushBack(2);
	stack.PushBack(3);
	stack.PushBack(4);
	stack.PushBack(5);

	cout << "Stack size : " << stack.Size() << endl;
	cout << "Top element : " << stack.Top() << endl;
	
	stack.PopBack();
	stack.PopBack();

	cout << "Stack size : " << stack.Size() << endl;

	stack.Show();

	stack.Clear();
	if ( stack.IsEmpty() )
	{
		cout << "Stack is empty" << endl;
	}
	else
	{
		cout << "Stack is not empty" << endl;
	}
	system("@pause");
}
Exemplo n.º 2
0
Arquivo: othello.cpp Projeto: gumgl/C
void Othello::MakeAIMove()
{
	int biggestGain = -4 * BOARD_SIZE * gameType; // Start with a really low value because after many moves, we could end up with biggestGain being negative
	int currGain;
	int depth;
	COORD move;
	Stack bestMoves;
	
	switch (gameType)
	{
	case 1:
		depth = 0; // Evaluate no move (play any valid move)
		break;
	case 2:
		depth = 1; // Evaluate wins by this move only
		break;
	case 3:
		depth = 2; // Evaluate wins by this move and the opponent's move
		break;
	case 4:
		depth = 5; // Evaluate wins by this move, the opponent's move and your next move
		break;
	}

	for (int row = 0; row < BOARD_SIZE; row ++) // Rows
	{
		for (int col = 0; col < BOARD_SIZE; col ++) // Columns
		{
			if (ValidMove(row, col)) // If move is valid
			{
				currGain = MoveValue(row, col, depth);
				move.Y = row;
				move.X = col;
				if (currGain > biggestGain) // If we found a new best move
				{
					biggestGain = currGain;
					bestMoves.Clear(); // Remove all the older moves, because this one is better
					bestMoves.Push(move); // Add this move to the stack
				}
				else if (currGain == biggestGain) // If this move is as good as the best one
					bestMoves.Push(move); // Add it to the stack
			}
		}
	}
	move = bestMoves.GetRandom();
	MakeMove(move.Y, move.X);
}
Exemplo n.º 3
0
Arquivo: main.cpp Projeto: Prosv/tasks
int main(int arg, char* argv[])
{
    Stack<int> S;
    int x;
    S.Push(1);
    S.Push(2);
    S.Push(3);
    x = S.Top();
    std::cout << x << std::endl;
    S.Pop();
    x = S.Top();
    std::cout << x << std::endl;
    S.Clear();
    S.Push(3);
    x = S.Top();
    std::cout << x << std::endl;
    S.~Stack();
    std::cin.sync();
    std::cin.get();
    return 0;
}