C++ :: Strategy Pattern Paradox - Algorithm To Decide Winner Of The Game
Feb 6, 2015
I've reached some sort of paradox while writing my small game. I need an algorithm to decide the winner of the game, but it's a fairly complicated task so i decided to delegate the responsibility to a strategy object, and code a naive(inefficient) algorithm to begin with, then i can easily swap the algorithm for a more efficient one later.
The problem is, that the strategy object needs to know the game, and the game needs to know the strategy object, but as you can see there is no way of doing that since i need to create one object before i create another.
//Wrong code illustrating the concept
Winner_strategy * winner_strategy;
Game * game;
winner_strategy = new Winner_strategy(game);
game = new Game_impl{winner_strategy};
BTW i know that it's best pratice to use unique_ptr, but i don't think it will make a difference here?
Is there some way to express this mathematically so that I do nto have to use a table lookup? I know this sounds like I am an idiot, but I can not figure out an obvious algorithm.
I am creating a reaction game using a series of lasers and LRDs and need to make a function which waits for a specific pin in portb to be triggered high before it can move onto waiting for the next pin to be triggered. The time lasped before the "game loses" needs to get exponentially faster as the game goes on.
I am using statements such as if(input(PIN_B0)==1 generate_tone(G_note[2], 1000); but unsure how to write in c "wait x amount of time, if trigger move onto next random pin or no trigger go to lose function.
I'm working on my first video game. So far I have a few classes in the game starting with the Game class which includes a list of GameObjects (another class). There are several classes that inherit from GameObjects used to implement things like bullets, explosions, various enemy types, etc.
The game essentially iterates through the list of GameObjects to update/render them. I would like to provide access to the Game's list of GameObjects inside another class (like the Bullet class) so I can put new objects on the list. For example, when a bullet hits, I want to add an explosion to the Game's GameObject list it can be updated/rendered.
How this should be setup? I was considering adding a pointer to the Game or GameObject list to the GameObject class (and methods to access it), but I was wondering if there is a better way to set this up?
I would like to make a program for calculating the total price of a game station, and a game. I made a program like this for just the price of a game in class, but I want to make one that does the game system as well.
I've been working on this code that should be looking like
1 3 5 3 1 3 5 7 5 3 5 7 9 7 5 3 5 7 5 3 1 3 5 3 1
but mine appears like this
1 3 5 3 1 3 5 7 5 3 5 7 9 7 5 3 3 5 7 9 1 3 1 3 5
This is the code I've got for now, I just don't know which logic I need to fix
int main(){ int r; cout << "Rows?" << endl; cin >> r; for (int i = 1; i <= r; i+=2){ for (int j = i; j <= r+i; j+=2){ cout << j<< " "; } for (int k = i+2; k >= i-1; k-=2){
I'm trying to output a pattern using loops. The pattern is a plus symbol made of 3 rows of 5 x's followed by 3 rows of 15 x's and finally 3 rows of 5 x's.
I can get the program to output all 9 rows with 5 x's but I don't know how to do the 3 rows of 15 in the middle. I have tried a while loop and also an if statement but nothing seems to work.
i have a .txt file with a bunch of numbers(1...99), millions of them, and i would like to make a program that recognizes patterns(if exists, i don't know) of numbers in this file. What will be the starting point? How could i do that? I read i could do that with Neural Network. Is there other way?
I am looking to write a program that, given a particular word, looks at a plain text document and gives a list of words that appear within x words of the given word along with a count of how many times it appears.
Do I need to use regex to do the pattern matching here? Is there a particular data structure that I should use that is particularly suited to a task like this? I don't want to reinvent the wheel, it seems like there should be libraries that would already do this sort of thing but searches have turned up nothing.
So, I'm going to write a recursive function for a asterisk pattern but I'm stuck figuring out how to create a stopping case for it, better yet, I'm unable to describe the pattern completely.
* Every odd row has 1 * with 1 incremented white space
* Every "pair" of asterisks equals 8 total (EX. 8 one pair *'s, 4 two pair *'s, 2 four pair *'s)
Unfortunately, that's all I got. how I can represent this as I function. Once I figure out what my stopping case should be, I think I can do the coding on my own.
In my UOW class I have the public property ProductRepository. Now my idea was instead of creating a public property for every repository that I have, I created the generic method GetRepository<T> to dynamically create repositories.
Do you think that this change will have bad side effects. I think that it will improve the maintainability of the code.
I am working on some coursework for university at the moment, and one of the questions asks me to 'write a function that will generate the following pattern using nested looping techniques.'
#include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; class singleTon {
[Code] ....
this is a singleton pattern first,it doesn't matter, why I could delete this pointer twice?because the gcc compiler?That mean in the surface, "delete pInstance1;" this movement just mark the memory pInstance1 has been deleted but not real?does any one encounter this phenomenon?
I need to design an interface(a function prototype) that takes an argument which is used to pass information. The information can be passed by independent modules and third party softwares and hence can vary today and in future.
Basically, the function interface(arg1, info)caters a niche service to many independent applications and needs to process based on requirements passed by applications in the argument(info, in example).
I am looking for a design pattern for the function parameter - info.
Should I use a void pointer that can be casted to respective application specific class in the function ? will this be a good C++ design ?
or should I take this parameter to be a pointer to a generic abstract class that points to the respective application specific specialization ?
Do we have some design pattern to address this so as to handle other unforeseen challenges ?