C++ :: Realization Of Lee Algorithm In Game
Nov 19, 2013I wont search realization of Lee algorithm in Game(2d turn-Based Strategy 20 x 30 cells),need AI on C++ ???
View 1 RepliesI wont search realization of Lee algorithm in Game(2d turn-Based Strategy 20 x 30 cells),need AI on C++ ???
View 1 Repliesdesigning an algorithm forHangman game.
I've got everything I need that is expected of my program except this.
When the user starts the game they will have these letters available to them:
"abcdefghijklmnopqrstuvwxyz"
Now if they were to guess 'a' it should look like this:
"-bcdefghijklmnopqrstuvwxyz"
then if they were to guess 'k':
"-bcdefghij-lmnopqrstuvwxyz"
and so forth.
As far as I'm understand we have only access to .h files of elements of STL. So other words in MS VC 2010 we haven't opportunity to see exact implementation of elements of STL. Where I can find implementation of STL elements or substitute algorithm that do the same thinks like stack from stl
View 2 Replies View RelatedI 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'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?
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.
View 7 Replies View RelatedI am writing a simple console-based tic-tac-toe game. I am trying to write a function to check whether someone has won the game.
The board data is saved in an array called board: Code: int board[3][3] with each element corresponding either to an empty spot, an X, or an O, using the numbers 0, 1, and 2, respectively. For clarity:
Code:
#define EMPTY 0
#define X 1
#define O 2 Here is my function: Code: int check_state(int board[3][3]) {
int winner = 0;
[Code].....
A few days ago I got a "bright idea" to see if I could match a string, with an arbitrary length from 1 to 12, to its formulated sequence by using an algorithm to find all possible combinations of the integer combinations from 0 to 9 at each length (1 to 12).
Example: Desired numerical combinations from integers 1 to 3:
At Length 1:
1, 2, 3
At Length 2:
11, 12, 13, 21, 22, 23, 31, 32, 33
At Length 3:
111, 112, 113, 121, 122, 123, 131, 132, 133, 211, 212, 213, 221, 222, 223, 231, 232, 233, 311, 312, 313, 321, 322, 323, 331, 332, 333
And so on until the nth length (in my case a length of 12).
First off, I would like to say that this is not as easy as I thought. I clearly underestimated the problem seeing as I've spent hours attempting to write a working algorithm, but feel like I've made no progress.
Here are a few of my attempts:
Attempt 1:
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
[Code]....
I can't exactly explain this one. It works if the length is 2 or less; however, the order of the output is horrendous.
Attempt 3: I tried using recursion, but only found myself getting more and more lost the further I tried developing my function. Cannot find my work for this attempt.
I would really like to figure this out on my own, but I am very stuck as you can see. I also lack time that I can spend working on this since im a full time student.
I wrote a version of find_all() which searches through containers for matches and returns another container that holds iterators pointing to each match. When I compared what I wrote to what the authors of Professional C++ wrote, I found the two find_all() functions to be very different.Here they are:
//Mine
template<typename Iterator, typename Predicate>
std::list<Iterator> find_all
(Iterator front, Iterator back, const Predicate& match) {
std::list<Iterator> toreturn;
for(; front != back; ++front) if(*front == match) toreturn.push_back(front);
[code]...
I have VRP algorithm written in C++, run with command prompt Windows. input (command line) -> VRP.exe -> output (txt file)
Now I want to built a website to run it as SaaS. How to run an exe application(compiled c++) in server used as Saas? What kind of programming do I have to use? Ruby or html5 or others? I don't know how to start.
i was trying to achieve a better way of game looping. so i have a game loop algrithm. but i dont think its quite good. i want it to be better.
here is my algorithm
bool quit = false;
while(quit == false) {
while(blah blah events)//here we hold events {
if(the user want to quits) {
quit = true;
[code]....
To construct and write down algorithm of determination of the sum of squares of consecutive integers with recursion use. I tried to do something:
public static int RecSumSquare(int x, int n)
{
if (n < 0) throw new ArgumentException("n should be greater than zero");
if (n == 0) return 0;
else return x*x+RecSumSquare(x, n - 1);
}
But I don't know as the beginning and the end of this algorithm will look.
I'm still a beginner at C++ programming, I have tried to implement some optimization algorithms (related to database) in C++, I cannot say it is going as far as I thought it will be, some errors does not even make sense, I will cut to the chase, I need to implement SA (Simulated Annealing) in C++, SA, which is an example of the Randomized Algorithms, functions on the concept of randomness and probability. In addition, I searched the internet with no (let say "accurate") code that might give me insight on how to begin, I only found one code for SA that I could understand, and edited it (which will be shown below), still looking to enhance and correct it more.
The code for SA is as follows:
Code:
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <cmath>
[Code] .....
If the concept of Simulated Annealing is not clear, you may refer to the following papers which can be found in a simple Google search: Simulated Annealing Algorithms: an overview.An Introduction to Interacting Simulated Annealing. Query Optimization (there is a sub-section for Simulated Annealing in this paper that explains SA briefly) ....
I'm trying to draw and pivot a rectangle. How to get the new coordinates if I turn it 90 degree for example?
From this:
To this:
This is not good because it will reduce it in size.
Code:
int size = 50;
if(b) // draw rectangle
{
POINT points[4] =
{{xCoord, yCoord},
[Code] ....
Trying to multiply to matrixes using the following algorithm,
Code:
ABrec(A,B)
n=A.rows; //n must be multiple of 2
C is a new n*n matrix.
if(n==1)
C[0][0]=A[0][0]*B[0][0];
[Code] ....
but the code doesn't work !!!
Now I know there's a simple way to calculate highest value. But here i have this algorithm which i understood part of it.
I know that *largest is point to the first element of begin which is 5. so in the first if statement its 5<5 at the first iteration ?
// i marked the parts i didnt understand with " //"
Code:
#include <stdio.h>
int *print(int *begin ,int *end ){
if(begin==end)
return 0;
int *largest = begin;
[Code] ....
i can't seem to get this merge sort to work. running through gdb though;
Code:
*Filename: mergeSort.c
*Usage: This implements merge sort algorithm to sort and array of numbers.
*/
#include <stdio.h>
#include <stdlib.h>
}
[code]...
write an algorithm using stack to determine if an input of string is in the form xCy where y is the reverse of x.x and y are strings of A and B. eg : AABACABAA
View 8 Replies View RelatedI'm trying to implement the flocking algorithm in C++. I've tried to implement it myself by making all the particles 'home-in' on the player. When 2 particles then collide within their larger bounding boxes they home-in to each other. And when the 2 particles are actually touching they repel each other until they are outside of their bounding boxes and find another particle to home-into.when I run my application the particles all home into the player and come to a stand still along the Y-axis above the player.
All the particles in question are stored in a Vector, with a pos and velocity.
for(int i = 0; i < swarm.size(); i++) {
for (int j = 0; j < swarm.size(); j++) {
if (swarm.at(i)->getParticleModel()->getPosition().x < gameObjects.front()->getParticleModel()->getPosition().x) {
if (swarm.at(i)->getParticleModel()->getTouching() == false)
[code]....
I made this program in C++ that should, by a genetic algorithm, build a word identical to the initial one improving itself recursively.
The code is:
main.cpp
#include <stdio.h>
#include <cstdlib>
#include "Genetic.h"
using namespace std;
[Code] ....
The problem is: when running with gdb it gave me this
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
CREATA LA PRIMA POPOLAZIONE
PARTE L'EVOLUZIONE
TROVATO BEST: fzlrq
TROVATO BEST: hglhe
Program received signal SIGSEGV, Segmentation fault.
0x000000000040720e in Genetic::Gene::Gene (this=0x7fffff7ff030) at Genetic.h:20
20 struct Gene {
The line corresponds to the struct declaration. Every 1000 executions it runs well.
I am looking for a compression algorithm which compress sequence of random numbers (will be in sorted order but some of the numbers may be missing). The compressed data will be sent to other component where decompression will take place.
View 5 Replies View RelatedAny simple example of deletion from the end here is the algorithm
1. If n=0 then array is underflow step
2. A (UB) <------- null
UB <---- UB1
3. Stop
Example:
Suppose array
Arr[0]=5 , Arr[1]=8 , Arr[2]=10 , Arr[3]=7
After Deletion
Arr[0]=5 , Arr[1]=8 , Arr[2]=10
How to delete the last element of array?
Genetic Algorithm Library in C++? I looked for in the web, there are a lot of them, have you tried some? Is there one up to date or with a good community?
View 1 Replies View RelatedHow to write Algorithm / Design
View 7 Replies View RelatedI've been stuck on a divide a conquer algorithm problem for about an hour now, and I'm not sure how to solve it. I need to use divide-and-conquer to implement an algorithm that finds the dominant element of an array of positive integers and returns -1 if the array does not have a dominant element (a dominant element is one that occurs in more than half the elements of a given array).
No sorting may be used, and the only comparison that may be used is a test for equality.
I understand the general process I need to follow to solve this problem, but I'm not sure exactly how to convert my thoughts to code. I know that if a number x is the dominant element of an array A, the x must be the dominant element in either the first half of A, the second half of A, or both.
Here is what I have so far.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int find_dominant(int *A, int p, int r) {
[Code] ....
The program must run in O(n log n) time.