• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Chris R

Member
Is it standard practice to use the library toString instead of creating your own toString? We were taught to use our own toString() method.

I think this only applies if you are creating your own objects or want more detailed info about an object. No reason to reinvent the wheel when it comes to standard datatypes like ints.
 

pompidu

Member
I think this only applies if you are creating your own objects or want more detailed info about an object. No reason to reinvent the wheel when it comes to standard datatypes like ints.

Ok yeah thats what I meant. Just couldn't tell from the example if that's what he was doing.
 
Any particular reason to use Boost in c++ anymore? Looking through it it seems there are a lot of built in functions in the new standard that take care of what boost does/did.
 

squidyj

Member
It's reversi, kinda hard to explain but everytime a player places their dot on the board,it checks the opponents dots diagonally and changes any dots up to that point.

if I understand correctly a valid move in reversi is one that annexes at least one opposing piece on the vertical, horizontal, or diagonal. I'm not sure what you're have trouble with though. is it just flipping the colors between point a and point b?
 

pompidu

Member
It's reversi, kinda hard to explain but everytime a player places their dot on the board,it checks the opponents dots diagonally and changes any dots up to that point.

This site has a nice explanation to how recursion works. It's in c++ but it'll help you understand what is going on because I'm not really sure if you don't understand it at all or just how it is applied to that game.
http://www.cprogramming.com/tutorial/lesson16.html
 

Big Chungus

Member
if I understand correctly a valid move in reversi is one that annexes at least one opposing piece on the vertical, horizontal, or diagonal. I'm not sure what you're have trouble with though. is it just flipping the colors between point a and point b?

Yup

This site has a nice explanation to how recursion works. It's in c++ but it'll help you understand what is going on because I'm not really sure if you don't understand it at all or just how it is applied to that game.
http://www.cprogramming.com/tutorial/lesson16.html

Thanks!
 

pompidu

Member
I'm really shitty at recursion myself but. My guess is he wants you to determine the direction, count the number of chips in that direction (length). Subtract the two chips that a person has player (white) from the total length of the chip placement (length - 2). Then flip those chips individually to white and decrement the length of the chip by one, length--, until length == 0. I have no idea if that is how the game actually works but that looks like something I would do. Maybe someone can clear that up lol.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
When I did a reversi program I checked whether a move was valid iteratively (with loops).

What is the recursive method like?

Or are you using recursion to see if a move is a good move or a bad move?
 

squidyj

Member
Yup



Thanks!

if you know point a and point b and you know the move is valid. then you know the direction from point a to point b ({+x} {+x +y} {-y} etc) and all you need to do is start at the first opponent colored piece on that path then just keep calling the recursive function from within itself until you get to a square with a friendly colored piece (this will obviously be point b).

I don't really get it though. if anything figuring out if a move is valid would be the hardest part.
 
I finished my compiler like a boss. I told my professor I wasn't going t implement CASE. He goes..why? I looked him straight in the eye and said "nah aint nobody got time for that."

I managed to get GOTOs working too.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Has anyone ever tried the online courses offered by MIT Opencourseware?

Are they any good? I'm looking to practice some stuff but I'm pretty bad at self study without some kind of direction in mind so I think a course list is good for that.
 

Hellix

Member
I was looking up some interview questions since I have my first programming interview on Wednesday. It is a Javascvript/C# job, and even though I have didn't list those two languages on my resume, they requested an interview. I'm not sure if I'll get the job, I am mainly going because I think it will be a good experience.

I want to get an entry-level position as a programmer/developer, but I am nervous about these interviews. I fudged my first interview where I had to do an Aptitude Test which evaluated my math and pattern recognition skills. I was rusty on my algebra, so I did terrible on the test. It didn't help that the evaluator was right in front of me and every section had a bunch of questions while being timed. I was also tired and anxious going into that test, since it was my first time interviewing for a job in my field, but I am just making excuses for myself. I am hoping maybe a programming-specific interviewing process would be better/easier for me.
 
Has anyone ever tried the online courses offered by MIT Opencourseware?

Are they any good? I'm looking to practice some stuff but I'm pretty bad at self study without some kind of direction in mind so I think a course list is good for that.

I'm doing an academic re-exploration using OCW right now. I find the entire idea of course content available online to be utterly fascinating.

Just a note. Not all of the courses are available in video lecture format, but it appears that at least a good portion of them are. You'll find the introductory work there, but also their courses on data structures, algorithms, and a few other topics. And also remember that OCW is but one resource available. You can fill in gaps with offerings from other schools such as Stanford and UC Berkeley. And the great thing is you can find their materials and more on iTunes U.

I went through OCW's 6.00 and then skipped over to re-learn Calculus (18.01) and found that the some of the algebra and a lot of the trig were kicking me in the teeth (years of lack of use) after about 5 lectures or so, so I started looking for materials there. Found a College Algebra course from Missouri State, which I am about through with. Blew through that in about a week, actually. Then going to refresh myself on some trig and then back into calculus. Why? Because! I'm a reasonably intelligent person and I feel somewhat ashamed that I have forgotten so much math.
 

pompidu

Member
if you know point a and point b and you know the move is valid. then you know the direction from point a to point b ({+x} {+x +y} {-y} etc) and all you need to do is start at the first opponent colored piece on that path then just keep calling the recursive function from within itself until you get to a square with a friendly colored piece (this will obviously be point b).

I don't really get it though. if anything figuring out if a move is valid would be the hardest part.

Well, what I would do with my limited knowledge, setting the starting count for black to like "blackStart" , check where the white chip is last placed and go through each direction (vertical, horizontal, diagonal)and determine if it encounters any white chips (and you would have to do this for each white chip since I believe you can make a corner and flip two rows at the same time). after all those ifs/loops etc, if blackStart.equals(getBlackCount) then return false, if not, check for any moves possible (to determine if the game ends) then count all the colored chips. IDK lol
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Just a note. Not all of the courses are available in video lecture format, but it appears that at least a good portion of them are.
Not a problem at all. I'm deaf so the videos wouldn't work for me anyway without subtitles (which some of them have apparently).

You'll find the introductory work there, but also their courses on data structures, algorithms, and a few other topics. And also remember that OCW is but one resource available. You can fill in gaps with offerings from other schools such as Stanford and UC Berkeley. And the great thing is you can find their materials and more on iTunes U.
So far I'm looking at:

6.837 - Computer Graphics
6.088 - Introduction to C Memory Management and C++ Object-Oriented Programming
6.046J / 18.410J - Introduction to Algorithms (SMA 5503)
OCW - Linear Algebra

Thanks for the ringing endorsement, I wasn't sure this is what I wanted but I'm definitely confident now.
 

squidyj

Member
Well, what I would do with my limited knowledge, setting the starting count for black to like "blackStart" , check where the white chip is last placed and go through each direction (vertical, horizontal, diagonal)and determine if it encounters any white chips (and you would have to do this for each white chip since I believe you can make a corner and flip two rows at the same time). after all those ifs/loops etc, if blackStart.equals(getBlackCount) then return false, if not, check for any moves possible (to determine if the game ends) then count all the colored chips. IDK lol

i would just... imagine a bool place(x, y) function. that looks in each direction and if there is
an enemy color piece in the next position in that direction begin recursing in that direction.

for the recursive function, recurse downward as you meet enemy pieces, if you exit the array or reach an empty space return false back up. if you meet a white piece return true back up.

so if we call the recursive function bool check(x, y, dx, dy) it would call check((x + dx), (y + dy), dx, dy), if that call returns true then it would set the color of the piece at x, y and return true, otherwise it would leave the color of the piece as is and return false back up the chain.

the initial calling function place(x, y) could then just OR all the results together and if any are true then the product will be true, meaning it's a valid move and the piece is placed.
 

pompidu

Member
i would just... imagine a bool place(x, y) function. that looks in each direction and if there is
an enemy color piece in the next position in that direction begin recursing in that direction.

for the recursive function, recurse downward as you meet enemy pieces, if you exit the array or reach an empty space return false back up. if you meet a white piece return true back up.

so if we call the recursive function bool check(x, y, dx, dy) it would call check((x + dx), (y + dy), dx, dy), if that call returns true then it would set the color of the piece at x, y and return true, otherwise it would leave the color of the piece as is and return false back up the chain.

the initial calling function place(x, y) could then just OR all the results together and if any are true then the product will be true, meaning it's a valid move and the piece is placed.

damn lol. gonna find source code for this game and see how they do it. i like your way though.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Here's how I did it:
Code:
public boolean legalMove(int r, int c, int color, boolean flip) 
{
	boolean legal = false;
		
	if (board[r][c] == 0)
	{
		int posX;
		int posY;
		boolean found;
		int current;
			
		for (int x = -1; x <= 1; x++)
		{
			for (int y = -1; y <= 1; y++)
			{
				posX = c + x;
				posY = r + y;
				found = false;
				current = board[posY][posX];
					
				if (current == -1 || current == 0 || current == color)
				{
					continue;
				}
					
				while (!found)
				{
					posX += x;
					posY += y;
					current = board[posY][posX];
						
					if (current == color)
					{
						found = true;
						legal = true;
							
						if (flip)
						{
							posX -= x;
							posY -= y;
							current = board[posY][posX];
								
							while(current != 0)
							{
								board[posY][posX] = color;
								posX -= x;
								posY -= y;
								current = board[posY][posX];
							}
						}
					}
					else if (current == -1 || current == 0)
					{
						found = true;
					}
				}
			}
		}
	}

        return legal;
}

Although now that I think about it, a recursive method would've been a lot more elegant.
 

squidyj

Member
Here's how I did it:

Although now that I think about it, a recursive method would've been a lot more elegant.

Code:
boolean place(int x, int y, Player p)
{
	boolean isValid = false;
	if((board[x][y] != empty) || !inRange(x, y))
		return false;
	for(int i = -1; i < 2; i++)
		for(int j = -1; j < 2; j++)
			if(inRange((x+i), y+j) && (board[x+i][y+j] != p)) //will recurse on empty spaces and fail immediately
				isValid = isValid || check((x+i), (y+j), i, j, p);
	if(isValid)
		board[x][y] = p;
	return isValid;
}

boolean check(int x, int y, int dx, int dy, Player p)
{
	if((board[x][y] == empty) || !inRange(x, y))
		return false;
	if(board[x][y] == p)
		return true;
	if(check((x + dx), (y + dy), 
dx, dy, p))
	{
		board[x][y] = p;
		return true;
	}
	else
		return false;
}

boolean inRange(int x, int y)
{ 
	return ((x >= 0) && (x < board.length) && (y >= 0) && (y < board[0].length));
}

well, if we're gonna post code.....
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Beaten but whatever. POSTING ANYWAY.
Code:
bool LegalMove(int r, int c, int x, int y, int color, bool flip)
{
	if (board[r][c] == color)
	{
		return true;
	}
	if (board[r][c] == EMPTY)
	{
		return false;
	}
	
	if (LegalMove(r+x, c+y, x, y, color, flip))
	{
		if (flip)
		{
			board[r][c] = color;
		}
		return true;
	}
	return false;
}
 

hateradio

The Most Dangerous Yes Man
Here's how I did it:

Although now that I think about it, a recursive method would've been a lot more elegant.
If I see the word elegant to describe a recursive method again, it'll be too soon. It makes me what to kill someone.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Maybe he's been reading too much xkcd.

I can empathize.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
How about ostentatious?

Can I describe a recursive solution as "ostentatious"?
 
Here's how I did it:
Code:
public boolean legalMove(int r, int c, int color, boolean flip) 
{
	boolean legal = false;
		
	if (board[r][c] == 0)
	{
		int posX;
		int posY;
		boolean found;
		int current;
			
		for (int x = -1; x <= 1; x++)
		{
			for (int y = -1; y <= 1; y++)
			{
				posX = c + x;
				posY = r + y;
				found = false;
				current = board[posY][posX];
					
				if (current == -1 || current == 0 || current == color)
				{
					continue;
				}
					
				while (!found)
				{
					posX += x;
					posY += y;
					current = board[posY][posX];
						
					if (current == color)
					{
						found = true;
						legal = true;
							
						if (flip)
						{
							posX -= x;
							posY -= y;
							current = board[posY][posX];
								
							while(current != 0)
							{
								board[posY][posX] = color;
								posX -= x;
								posY -= y;
								current = board[posY][posX];
							}
						}
					}
					else if (current == -1 || current == 0)
					{
						found = true;
					}
				}
			}
		}
	}

        return legal;
}

Although now that I think about it, a recursive method would've been a lot more elegant.
Not nesting logic statements 7 layers deep would've been "a lot more elegant".

As a general rule of thumb, if you hit 3 you did something wrong. Maybe even 2. Programming languages support functions/subroutines, use them!
 

Haly

One day I realized that sadness is just another word for not enough coffee.
As a general rule of thumb, if you hit 3 you did something wrong. Maybe even 2. Programming languages support functions/subroutines, use them!

I'll keep that in mind next time I encounter it.

EDIT: I SAW THAT EDIT
 
I'll keep that in mind next time I encounter it.

EDIT: I SAW THAT EDIT
My edit was overbroad so I killed it!

Specifically, what I was getting at is that recursion is fairly overrated in a "solve this algorithm with recursion!" context. That's mostly a learning construct to explain the pattern. In real world situations it tends to be an emergent phenomenon -- e.g. in OOP, for example, you might have an object A that calls an object B that calls an object C that calls an object D that invokes a method that calls back to A. Bam, recursion!
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Well actually, in that very same project I used recursion for building a tree.

CODE TIEM
Code:
/**
 *  Creates a tree to explore potential moves
 *
 *  @param    parent   The node to expand 
 *  @param    depth    A counter to keep track of the depth of the tree.
 *
 *  @return   parent   The parent with any new children
 */
public Node buildTree(Node parent, int depth)
{
	// Check to see if there is still more to expand and if the game isn't done
	if (depth > 1 && parent.end == -1)
	{
		// Decrease the depth count
		depth--;
		
		// Determine the subsequent turn ahead of time
		int nextTurn;
		if (parent.turn == Game.BLACK) 
			nextTurn = Game.WHITE;
		else 
			nextTurn = Game.BLACK;
		
		// Searches for legal moves
		for (int i = 1; i <= 8; i++)
		{
			for (int j = 1; j <= 8; j++)
			{
				// Store the current move being checked
				Move currentMove = parent.state.pointMove(i, j, parent.turn, false, pointTable);
				
				// If it is legal
				if (currentMove.legal)
				{
					// Create a Game object that attempts the current move
					Game futureGame = new Game(parent.state);
					futureGame = makeMove(futureGame, false, parent.turn, currentMove);
					
					// Create a Node that holds the current move, the future game
					Node newNode = new Node(currentMove, futureGame, nextTurn);
					
					// The position value of the new node is the number of points gained by the move leading up to that node
					newNode.position = currentMove.points;
					
                                        // Check the number of potential moves of the future game
					newNode.mobility = mobilityCheck(futureGame, nextTurn);
					
                                        // Checked whether or not the future game has ended
					newNode.end =  endCheck(futureGame);

					parent.addChild(newNode);
					newNode.parent = parent;
				}
			}
		}
	
		// Build a sub tree for each child
		for (Node n : parent.children)
		{
			n = buildTree(n, depth);
		}
		
		// Calculate mobility while recursing backwards
		parent.mobility = parent.children.size();
	}
	return parent;
}

Creates a tree of all possible moves up to 3 turns ahead. Then I have some other functions for choosing the best moves using some weights and heuristics. Has a 98% win rate against random strategy at depth = 3, but at depth = 4 it tanks to 80%, leading me to believe there's a huge bug somewhere in there.
 

Kalnos

Banned
Any other fresh grads around? Not entirely sure what to fill my resume with. I have one year of software development experience at a medical records company but other than that all I can think of to put on my resume are course projects.
 

usea

Member
Any other fresh grads around? Not entirely sure what to fill my resume with. I have one year of software development experience at a medical records company but other than that all I can think of to put on my resume are course projects.
Yeah, there's not a lot. I had some awards, the boring jobs I worked as a student, and some projects. I didn't have an internship.

Lots of companies are thrilled to hire fresh grads if they're competent.
 

d[-_-]b

Banned
Any other fresh grads around? Not entirely sure what to fill my resume with. I have one year of software development experience at a medical records company but other than that all I can think of to put on my resume are course projects.

Graduating this month hopefully, feel so unprepared... At least you have experience to show and course projects...
 

Kalnos

Banned
d[-_-]b;57458042 said:
Graduating this month hopefully, feel so unprepared... At least you have experience to show and course projects...

Surely your school made you do some sort of senior project or embedded systems type work. That's all I meant by course work. :p
 

squidyj

Member
Yeah, there's not a lot. I had some awards, the boring jobs I worked as a student, and some projects. I didn't have an internship.

Lots of companies are thrilled to hire fresh grads if they're competent.

Oh thank god, now all I have to do is make them think I'm competent :p
 

msv

Member
Got some ASP.NET AJAX UpdatePanel troubles.

I have UpdatePanels on the page, which show one of two images, A or B. Click A, then it becomes B, and vice versa. Default is A.

So now I click A and it becomes B, all good. Then I refresh the page. The item that was B is now A again, so it returned to the default value. So client side, it's A. But when I click it, server side, it says that it's B!! Then it 'reverts' to A, so the client doesn't even see a difference.

It seems that a refresh of the page isn't refreshing the updatepanels (but the refresh does load the default values on the updatepanels, say what?)? Is it possible to refresh the updatepanels server or client-side on page load?

edit: Mehhh, Firefox was the issue. Pressing F5 or the refresh button, doesn't refresh the page, instead it repeats the last action. UpdatePanels were shown according to Firefox cache :/
 
I am working on this content management system thing for a client and just as I am on the last scretch something vital comes to mind: The ActionScript VM can only handle files that are 700 megabytes big at one time, which totally breaks my import/export function, as one package could have videos, pdf's and images in it. And I literally have no time to re-do it.

Fucking sigh.
 

Lonely1

Unconfirmed Member
My problem is the following: My program has to generate a file and then send a shell call to another program that has to compute such file. However, due to lazy evaluation, the file isn't generated in time and the external program yields a file-not-found exception.

So, I tried to force strict evaluation by using seq: generateFile `seq` sendShellCommand, but that generates an empty file, so `seq` doesn't work with IO Monads. Any suggestions of how to make this work cleanly? I'm ashamed of being stuck on stuff like this. :/
 

Venfayth

Member
Hi duders, I have a couple questions

I've taken classes in programming before in college before I dropped out, so I'm very familiar with a lot of the basic concepts.

I'm kinda getting interested again, and I want to make some very basic visual games. My intuition says I should mess around with Direct X, so I'm downloading visual studio express 2012 and plan on maybe trying to follow a tutorial or something to get into it again.

Does anyone have any advice? Is there a reason to use C++ over C#? Should I not be bothering with Direct X?

I kinda just want to start with a pong style game and then go from there.

Any/all input is appreciated, thanks :B
 

nan0

Member
I don't know whether it's a good idea to directly work with DirectX, since it's not exactly an easy starting point for a beginner from my experience. XNA with C# is a viable alternative, although Microsoft stopped updating it. Other than that I think using an established 3D engine, such as OGRE or Panda3D (no need to reinvent the wheel), is easier to work with but maybe the 3D specialists here have some better suggestions. I had some good experiences with jPCT, but thats Java (Android version also exists).

Edit:
Even though XNA is no longer supported, it doesn't mean that it's not usable. It's great for quickly getting visible result, and the initial stuff you have to learn applies to most other engines and APIs anyway. I actually expect that MS presents a successor to XNA along the announcement or release of Durango.
 

Venfayth

Member
I actually have less interest in working with 3D than most people do, I guess. I'm more into 2D games. But it certainly couldn't hurt to work with it from an experience perspective!

Also, I think that XNA is a good idea, after looking in to it. Although it does suck it's no longer being supported. :(
 
Top Bottom