# Ars7c3

Member

26

189 Neutral

• Rank
Member

• Interests
Programming
1. ## Help with MiniMax Algorithm for Tic Tac Toe

Unfortunatley, that was not the issue. I tried it, but it exhibited the same behavior. The AI will block winning moves, but when it has a winning move it does not capitalize on it.
2. ## Help with MiniMax Algorithm for Tic Tac Toe

I am currently working on creating an AI player for tic tac toe. After researching, I discovered that the minimax algorithm would be perfect for the job. I am pretty confident in my understanding of the algorithm and how it works, but coding it has proven a little bit of a challenge. I will admit, recursion is one of my weak areas . The following code is my AI class. It currently runs, but it makes poor decisions. Could someone please point out where I went wrong? Thank You! import tictactoe as tic # interface to tictactoe game logic like check_victory class AI: def __init__(self, mark): self.mark = mark def minimax(self, state, player): #end condition - final state if tic.check_victory(state): if player == self.mark: return 1 else: return -1 if tic.check_cat(state): return 0 nextturn = tic.O if player == tic.X else tic.X #generate possible moves mvs = [] for i, mark in enumerate(state): if mark == tic.EMPTY: mvs.append(i) #generate child states of parent state scores = [] for mv in mvs: leaf = state[:] leaf[mv] = player result = self.minimax(leaf, nextturn) scores.append(result) if player == self.mark: maxelle = max(scores) return mvs[scores.index(maxelle)] else: minele = min(scores) return mvs[scores.index(minele)] def make_move(self, board, player): place = self.minimax(board, player) return place
3. ## Passing Objects

Your code is too coupled, which means that your classes are too dependent on each other. Coupling usually indicates a poor design. I advise you to read this. It is a good articles that explains coupling and how you can reduce it. It will save you a great deal of headaches later on in the development process.
4. ## Tutorial: Designing and Writing branching and meaningful Game Conversations in our game

Wow! This is really cool stuff, thanks for sharing!
5. ## problems with initializing my map

Thank You Brother Bob. I still have much to learn.  But then again, we're never done learning are we?
6. ## problems with initializing my map

I tried that, and it had the same result as before. It only works when the width, height, and layers are all the same. When, for example, i set the width and height to 10, and the layers to 3, it returns an error that says: vector subscript is out of range.
7. ## problems with initializing my map

Hey guys, so I am working on a simple level editor for a platform game I&#39;m making, and everything&#39;s been going smoothly up until now. I decided I wanted to have a 3d vector to allocate tiles for my editor instead of a 3d pointer because they are very difficult to understand( for me anyway). The level allocates correctly ONLY if the width, height, and layers of the level are all the same value, and that is what is stumping me. I would greatly appreciate it if someone could help me out.   //My vector container vector<vector<vector<Tile*> > >map; //How I'm allocating the map... in the Level constructor Level::Level(int tileWidth, string tilePath) { AskProperties(); AskFileName(); sheet.Init(tileWidth, tilePath); for(int l = 0; l < layers; l++) { map.resize(layers); cout << "Layer " << l << endl; for(int i = 0; i < height; i++) { map[i].resize(height); cout << endl<< "Row " << i << endl; for(int t = 0; t < width; t++) { map[i][t].resize(width); map[i][t].push_back(new Tile(t * sheet.GetTileSize(), i * sheet.GetTileSize(), false, sheet)); cout << "X " << t << endl; } } } } //How i am saving the level -- using integers to represent tile types void Level::Save() { cout << "NOPE" << endl; ofstream file(fileName.c_str()); for(int x = 0; x < layers; x++) { file << endl << endl << "Layer: " << x + 1 << endl << endl; for(int y = 0; y < height; y++) { file << endl; for(int z = 0; z < width; z++) { file << map[x][y][z]->GetType(); } } } }
8. ## Letting a probability of an object to appear in the scene...

Not the most efficient way, but it would work. In SFML, you could do something like this: Create a timer, get a random number using rand() between x and n, and set the timer to go off after the random number of seconds is up. After the timer goes off, you would execute whatever you wanted to happen. Here is a link to the SFML Timer page so you can learn more about it: http://www.sfml-dev.org/documentation/2.0/classsf_1_1Time.php.   If you're not using SFML, I'm sure you could easily apply it to another API.
9. ## Simple splash screen?

Are you looking to have different game states, such as a Splash Screen state, a Menu state, and a Playing state? Or are you simply asking how you would go about making a  transparent splash screen background?
10. ## 48 Hour Challenge Result

Wow, this is really good, although I got my butt kicked by space pirates.  Keep up the good work, and good luck on your engine!
11. ## !HELP! SFML Window Init Problems

Thank you Servant of the Lord, it worked! It was a Duh mistake.   *facepalm
12. ## !HELP! SFML Window Init Problems

Hello, I've had issues initializing sf::RenderWindow and cannot figure out why the program isn't working. I am getting an unhandled exception error. The program crashes right when i call the create function for RenderWindow. The code is below. Thanks in Advance!   //This is the whole Engine.h file #ifndef ENGINE #define ENGINE #include <string> #include <vector> #include <SFML/Graphics.hpp> #include <iostream> #include "Debug.h" using namespace std; class State; class Engine { public: void Init(int Width, int Height,string caption); void CleanUp(); void ChangeState(State *state); void PushState(State *state); void PopState(); void HandleEvents(); void Update(); void Render(); void Run(); bool Running(); void Quit(); sf::RenderWindow *Window(); private: sf::RenderWindow *m_window; vector<State*> m_states; bool m_running; int m_width, m_height; }; #endif //This is the Init function in the cpp file for Engine void Engine::Init(int Width, int Height,string caption) { Debug::Write("Starting"); m_states.clear(); Debug::Write("states cleared"); m_width = Width; m_height = Height; Debug::Write("w/h init"); m_running = true; Debug::Write("running = true"); m_window->Create(sf::VideoMode(Width,Height),caption); Debug::Write("!Engine initialization complete..."); }
13. ## Collision Detection HELP!

Thats not right either ^^^ i dont know y it wont let me post the correct code???
14. ## Collision Detection HELP!

I actually did include that in my code... for some reason it didn't upload that way. Here is the real code i use to detect collision. [source lang="cpp"]bool Collision(SDL_Rect A, SDL_Rect B) { //The sides of the rectangles int leftA, leftB; int rightA, rightB; int topA, topB; int bottomA, bottomB; //Calculate the sides of rect A leftA = A.x; rightA = A.x + A.w; topA = A.y; bottomA = A.y + A.h; //Calculate the sides of rect B leftB = B.x; rightB = B.x + B.w; topB = B.y; bottomB = B.y + B.h; //If any of the sides from A are outside of B if( bottomA <= topB ) { return false; } else if( topA >= bottomB ) { return false; } else if( rightA <= leftB ) { return false; } else if( leftA >= rightB ) { return false; } //If none of the sides from A are outside B else return true; }[/source]
15. ## Collision Detection HELP!

Okay, so i have been working on a pong game in order to test my very basic game engine, and everything that the engine is supposed to do it's doing. The problem is in the collision code, which is confusing considering I have used this very same code successfully in other games I have made. I honestly have no idea what the issue is, and I was hoping one of you guys could help me. I don't know if this would make a difference or not but I am using Dev C++. Here is the collision code and how it is used (BTW I made sure the SDL_Rect coordinates are correct) [source lang="cpp"]bool Collision(SDL_Rect A, SDL_Rect B) { //The sides of the rectangles int leftA, leftB; int rightA, rightB; int topA, topB; int bottomA, bottomB; //Calculate the sides of rect A leftA = A.x; rightA = A.x + A.w; topA = A.y; bottomA = A.y + A.h; //Calculate the sides of rect B leftB = B.x; rightB = B.x + B.w; topB = B.y; bottomB = B.y + B.h; //If any of the sides from A are outside of B if( bottomA <= topB ) { return false; } else if( topA >= bottomB ) { return false; } else if( rightA <= leftB ) { return false; } else if( leftA >= rightB ) { return false; } //If none of the sides from A are outside B else return true; }[/source] And here is how I call it in the main game loop: [source lang="cpp"] if(Collision(paddle2.GetRect(),ball.GetRect())) { cout << "Hit" << endl; } [/source]