|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On November 02 2012 11:28 simcaster wrote:Show nested quote +On November 02 2012 11:13 CarelessPride wrote: Hey I just started taking classes in programming and I have a few questions: 1. When video games are being developed do they create their own engine or do they buy the licenses off others already made engines? Also what are the common or efficient languages used to design video games?
The vast majority of games license an engine. C++ is commonly used to design engines and lighter scripting languages like lua and python are used for everything else. Show nested quote +On November 02 2012 11:13 CarelessPride wrote: 2. How long would it take to recreate a similar game to lets say starcraft 2 or Diablo 3. like no create design wise just recreate everything from scratch
It would take years and a large team to recreate a game of the quality of SC2 or D3.
How long would it take me to learn the skills needed to start?
|
On November 02 2012 11:53 CarelessPride wrote:Show nested quote +On November 02 2012 11:28 simcaster wrote:On November 02 2012 11:13 CarelessPride wrote: Hey I just started taking classes in programming and I have a few questions: 1. When video games are being developed do they create their own engine or do they buy the licenses off others already made engines? Also what are the common or efficient languages used to design video games?
The vast majority of games license an engine. C++ is commonly used to design engines and lighter scripting languages like lua and python are used for everything else. On November 02 2012 11:13 CarelessPride wrote: 2. How long would it take to recreate a similar game to lets say starcraft 2 or Diablo 3. like no create design wise just recreate everything from scratch
It would take years and a large team to recreate a game of the quality of SC2 or D3. How long would it take me to learn the skills needed to start? In order to work on something of SC2 scale, at least 3 years. Realistically more like 4-7 in order to get a job as a C++ software engineer at one of those studios. These are assuming you're obtaining a Bachelor's degree in CS, and a really good one at that.
|
On November 02 2012 11:13 CarelessPride wrote: Hey I just started taking classes in programming and I have a few questions: 1. When video games are being developed do they create their own engine or do they buy the licenses off others already made engines? Also what are the common or efficient languages used to design video games? 2. How long would it take to recreate a similar game to lets say starcraft 2 or Diablo 3. like no create design wise just recreate everything from scratch
As far as i'm aware almost all large commercial games are created in engines written primarily in C++ (with some delving down into assembly for further optimisation). A lot of companies lease these, due to the fact that creating a game engine will often cost as much if not more than what they pay to lease one, not to mention all the hassles that come with it, and the fact that it simply wont be as polished and bug free as one that has been worked on and patched for years. Though some games require a custom engine which once created can be either for solely personal use or designed in mind so that they can lease it out. A well known example of this would be the unreal engine made by epic, or cryengine developed by crytek.
Recreating any commercial game would take a lot of effort and time, something as polished (technically speaking, not balance) as starcraft and diablo would probably take a similar sized team around a few years (the main difficulty would be in recreating the game engine, which would need to be built from scratch to emulate the one blizzard has made.)
|
On November 02 2012 11:55 CecilSunkure wrote:Show nested quote +On November 02 2012 11:53 CarelessPride wrote:On November 02 2012 11:28 simcaster wrote:On November 02 2012 11:13 CarelessPride wrote: Hey I just started taking classes in programming and I have a few questions: 1. When video games are being developed do they create their own engine or do they buy the licenses off others already made engines? Also what are the common or efficient languages used to design video games?
The vast majority of games license an engine. C++ is commonly used to design engines and lighter scripting languages like lua and python are used for everything else. On November 02 2012 11:13 CarelessPride wrote: 2. How long would it take to recreate a similar game to lets say starcraft 2 or Diablo 3. like no create design wise just recreate everything from scratch
It would take years and a large team to recreate a game of the quality of SC2 or D3. How long would it take me to learn the skills needed to start? In order to work on something of SC2 scale, at least 3 years. Realistically more like 4-7 in order to get a job as a C++ software engineer at one of those studios. These are assuming you're obtaining a Bachelor's degree in CS, and a really good one at that.
3 seems a bit optimistic, i know i wouldn't want to hire someone for a project like that straight out of college / uni. We are talking a large professional undertaking with probably multi-millions in funding. If you skipped the degree, specialised your learning and built up a portfolio (by working in the industry for a few years) demonstrating your capability in that specific field it may be possible(even then without the degree, you face the reality of being turned down for people who have both the degree and experience). Still i would say to get onto a team that size, working on a project that large you would be looking at 5-6 years at a realistic minimum.
From what i've seen companies like blizzard won't even look at hiring someone as a programmer unless they have many years of experience in the industry already. They are pretty much the cream of the crop and can afford to be picky.
|
Rewrote that recursive function from the last page non-recursively here. Might have some performance hits, but no duplicates, and so no tracking for duplicates needed.
A brief summary... given a MaximumNumber and MaximumSum, calculate all the possible 1 or 2 set moves where their sum is less than or equal to MaximumSum.
ex. MaximumNumber = 4, MaximumSum = 6. Valid moves are {1} {2} {3} {4} {1,2} {1,3} {1,4} {2,3} {2,4}, since the summation of any of them are <= MaximumSum
void generateLegalMoves() { vector<int>temp;
for (unsigned int d = 0; d < board.size(); ++d) { // finds all the single moves if (board[d] <= maxSum) { temp.push_back(1); temp.push_back(board[d]); temp.push_back(board[d]); legalMoves.push_back(temp); temp.clear(); }
// finds all the double moves if ((d + 1) < board.size() ) { for (unsigned int n = (d + 1); n < board.size(); ++n) { if (board[d] + board[n] <= maxSum) { temp.push_back(2); temp.push_back(board[d]); temp.push_back(board[n]); legalMoves.push_back(temp); temp.clear(); } } } } }
I still feel like it can be done better recursively, but so far my efforts always end up with duplicate numbers and then trying to track for duplicate numbers which makes me think the non-recursive approach might end up performing just as well in the end.
|
@ESCPlan: your code examples use a board array but your problem description says you have a maximum number n and simply use (1...n) as available tokens to construct your sets -- which one is it?
also, please try to make clean code examples. Your example code looks like that whole vector pushback stuff is the complicated problem when all you are looking for is how to arrange the for loop counters and conditions..
oh and if ((d + 1) < board.size() ) is redundant. for (unsigned int n = (d + 1); n < board.size(); ++n) automatically skips that case because when you substitute the n<board.size() with the initialization n=(d+1), the for loop actually checks that exact condition automatically before executing.
|
On November 02 2012 14:00 EscPlan9 wrote:+ Show Spoiler +Rewrote that recursive function from the last page non-recursively here. Might have some performance hits, but no duplicates, and so no tracking for duplicates needed. A brief summary... given a MaximumNumber and MaximumSum, calculate all the possible 1 or 2 set moves where their sum is less than or equal to MaximumSum. ex. MaximumNumber = 4, MaximumSum = 6. Valid moves are {1} {2} {3} {4} {1,2} {1,3} {1,4} {2,3} {2,4}, since the summation of any of them are <= MaximumSum void generateLegalMoves() { vector<int>temp;
for (unsigned int d = 0; d < board.size(); ++d) { // finds all the single moves if (board[d] <= maxSum) { temp.push_back(1); temp.push_back(board[d] ; temp.push_back(board[d] ; legalMoves.push_back(temp); temp.clear(); }
// finds all the double moves if ((d + 1) < board.size() ) { for (unsigned int n = (d + 1); n < board.size(); ++n) { if (board[d] + board[n] <= maxSum) { temp.push_back(2); temp.push_back(board[d] ; temp.push_back(board[n] ; legalMoves.push_back(temp); temp.clear(); } } } } }
I still feel like it can be done better recursively, but so far my efforts always end up with duplicate numbers and then trying to track for duplicate numbers which makes me think the non-recursive approach might end up performing just as well in the end.
It doesn't matter whether you use your recursive approach to skip the {1,1} {2,2} ... {n,n} test cases. It's not going to make any noticeable difference whether you check those or not, even if you had just put a crude if x1 != x2 to skip that case.
Judging by your code, I would really consider making another function that returns a vector vector with the elements you want. It would make the code a lot less confusing to look through. In general, it's pretty impossible to track since your variables aren't that explicit and such.
You can do a few simple optimizations here and there, but your code isn't really clear about what variables are used for what purpose. Also, no one has any idea what board.size() means but you. :/
If you loop your second loop starting from the index your already started with, you will skip all the repeating cases. Then you only have to handle the {n,n} cases, which is also slightly trivial.
+ Show Spoiler [cheating] +
// solution
vector vector legal_moves(max_num, max_sum){ for x in 1 to max_num if x <= max_sum vector.add(x)
for x in 1 to max_num for y in x to max_num if x != y if x + y <= max_sum vector.add( new vector {x,y} )
return vector }
// better
vector vector legal_moves(max_num, max_sum){ for x in 1 to max_num if x <= max_sum vector.add(x)
for x in 1 to max_num - 1 for y in x + 1 to max_num if x + y <= max_sum vector.add( new vector {x,y} )
return vector }
Something like that. The max_num - 1 means you skip the {4,n} cases since it's pointless anyways. It also allows you to start the second loop at x + 1, so you don't have to skip checking the {n,n} cases. If you put max_number = 4 and max_sum = 6 vector should have {1} {2} {3} {4} {1,2} {1,3} {1,4} {2,3} {2,4} {3,4} in that order if I'm tracing properly. Sure, you can improve the performance of this by a bit, but really, is it really necessary? (Actually, I'm not sure about this statement)
Again, I emphasize making a function to perform this task, even if it's just for readability.
|
Hey I wrote some small C practice programs. Maybe some of you guys will have fun or find it useful to check them out: link. It'd be cool to compare solutions.
|
On November 03 2012 05:41 MisterD wrote: @ESCPlan: your code examples use a board array but your problem description says you have a maximum number n and simply use (1...n) as available tokens to construct your sets -- which one is it?
also, please try to make clean code examples. Your example code looks like that whole vector pushback stuff is the complicated problem when all you are looking for is how to arrange the for loop counters and conditions..
oh and if ((d + 1) < board.size() ) is redundant. for (unsigned int n = (d + 1); n < board.size(); ++n) automatically skips that case because when you substitute the n<board.size() with the initialization n=(d+1), the for loop actually checks that exact condition automatically before executing.
Ah, didn't think about that one line being redundant. About the confusion with board, and what it represents, and why I'm using the datatypes I'm using... well... it's a large project. Throughout this quarter I had to use a generic AI solver algorithm for various 2 player games.
I have a Solver template class that only has the SolveForBestMove(T GameType) function inside it. It solves for whatever GameType object I throw at it. Within the SolveForBestMove function, I have calls out to overloaded functions for each GameType. For instance, in the example I've been showing above, the game is called Crossout. I have a CrossoutGame class with overloaded functions from what is called within the generic Solver template. So for example, within Solver template, in it's recursive SolveForBestMove method:
if ( GameType.isFinalPosition() ) { // If it is a tie game, return 0 for the score if ( GameType.isTied() ) return NEUTRAL_MOVE_SCORE; // score of 0 for the move
//Checks players turn (To see if good or bad move) if ( GameType.getTurn() == FIRST_PLAYER_TURN ) return GOOD_MOVE_SCORE; //Returns score of +1 for the move
else return BAD_MOVE_SCORE; // Returns score of -3 for bad move } ... // calls GameType.getLegalMoves() and with a depth-first search recursively iterates // through the resulting position of each move and returns the score.
And then within Crossout:
// When there are no more legalMoves remaining, the final position has been reached // No more numbers can be crossed out. So whoever crossed out the last number // wins the game bool CrossoutGame::isFinalPosition() const { return (legalMoves.size() == 0) ? true : false; }
I've had each GameType use a vector<vector<int>> to store the Legal Moves, so I did the same for the Legal Moves of Crossout. The SolveForBestMove function explicitly expects a vector<vector<int>> when it calls GameType.getLegalMoves(), so each GameType (CrossoutGame, Connect3Game, etc) returns a vector<vector<int>> for the LegalMoves.
I am using a vector<int> for "board" in Crossout, since the game only requires me displaying it as a single line of integers. Like with the "1 2 3 4" example, the board has a size of 4, with board[0] == 1, board[1] == 2... board[3] == 4. It is a vector rather than an array because numbers are removed throughout the game and this allows me to constantly resize the array as needed.
For other games, such as Connect3 (Connect 4 with 3-in-a-row as the winning conditions), I use a vector<vector<int>> for "board".
It's fairly lengthy to post all the code I'm using... I was more curious with the recursive approach I tried last night that ended up running into duplicates. With the newer version, I'm fine with it as is, though there may be small improvements that can be made.
Thanks for the input. I'll remove the one redundant line anyways I apologize for the lack of clarity in the code in some areas. It's a small piece of a much larger project.
|
@EscPlan9: It's perfectly fine to re-use algorithms in bigger projects, but when making small examples you need to a) make sure you are correct on specifications - for instance using the board array instead of just numbers (1...n) is fundamentally different as it doesn't allow you to skip ahead in the algorithm without knowing if the number sequence in the array have holes (which i just assumed they do because otherwise the array would be pointless) or even worse if it isn't even a sequence in increasing order. Also, when extracting a piece of sample code from your large project, don't just copy/paste it 1:1 - take out the essential parts so readers can cope with the complexity as easily as possible. Yes it's a bit of extra work, but you want them to help don't you? ;D
As for your description of why array or vector: sounds a lot like you are trying to over-optimize. How many legal moves are there? if it's less than 100 i'd argue that it's completely pointless (performance wise) to aim for reducing the array size when moves become illegal. In fact, it's probably worse to do so because in addition to not having any benefits, it just makes your code needlessly harder to read, understand and maintain. As a general rule of thumb, do performance optimization after you implemented a solution, and only do it where needed. Micro-optimizations such as reducing a 100 entry array in size are generally bad.
|
Hello guys, I have more dumb questions.
1) I'll be doing a robotics project for a year, I don't know anything about hardware interaction but they'll teach me, however what I do need to know is C/C++. I know C decently well and haven't touched C++ but it seems like C++ would be preferable and it's seemingly used in a lot more places than C. Should I bend to Torvalds' divine will and stick to C or is C++ as beneficial as it seems?
2) C compilers for Windows? I'm used to make doing all the work for me, and using an IDE for compilation of small doodads is a waste of time. How do gcc on Windows best? MinGW? Cygwin?
|
On November 03 2012 19:21 Ruscour wrote: Hello guys, I have more dumb questions.
1) I'll be doing a robotics project for a year, I don't know anything about hardware interaction but they'll teach me, however what I do need to know is C/C++. I know C decently well and haven't touched C++ but it seems like C++ would be preferable and it's seemingly used in a lot more places than C. Should I bend to Torvalds' divine will and stick to C or is C++ as beneficial as it seems?
2) C compilers for Windows? I'm used to make doing all the work for me, and using an IDE for compilation of small doodads is a waste of time. How do gcc on Windows best? MinGW? Cygwin?
1) What does "decently well" mean? Are you confortable with pointers? Linked lists? Threads? Sockets? Sorting? Parsing? I don't know about C++ being used more than C, or even if it is used at all in robotics, but good knowledge of C will take you anywhere you want anyway so being very confortable with C will probably help you more than being decent in both C and C++.
2) Just use visual studio's ^^
|
Hi Guys, I work at a small software company ( only an accomodation job) and this company offers services through their website which is in php. Now my boss gave me the job to find a programm that is able to analyze php code and notice any flaws security-wise. I have found a programm called rats that would be capable but now I need to find phpcode with security flaws so i can test the programm. so my question is: does anyone have experience with automated php code analyzing and can recommend a tool for that purpose (it doesnt have to be free if its really good)? does anyone know where i can find dedicated false php code to test this rats-tool that i found?
thanks in advance
|
On November 03 2012 19:49 flexgd wrote: Hi Guys, I work at a small software company ( only an accomodation job) and this company offers services through their website which is in php. Now my boss gave me the job to find a programm that is able to analyze php code and notice any flaws security-wise. I have found a programm called rats that would be capable but now I need to find phpcode with security flaws so i can test the programm. so my question is: does anyone have experience with automated php code analyzing and can recommend a tool for that purpose (it doesnt have to be free if its really good)? does anyone know where i can find dedicated false php code to test this rats-tool that i found?
thanks in advance
Have you had a look here : http://stackoverflow.com/questions/4156157/tool-for-php-code-analysis ?
|
On November 02 2012 14:00 EscPlan9 wrote:Rewrote that recursive function from the last page non-recursively here. Might have some performance hits, but no duplicates, and so no tracking for duplicates needed. A brief summary... given a MaximumNumber and MaximumSum, calculate all the possible 1 or 2 set moves where their sum is less than or equal to MaximumSum. ex. MaximumNumber = 4, MaximumSum = 6. Valid moves are {1} {2} {3} {4} {1,2} {1,3} {1,4} {2,3} {2,4}, since the summation of any of them are <= MaximumSum void generateLegalMoves() { vector<int>temp;
for (unsigned int d = 0; d < board.size(); ++d) { // finds all the single moves if (board[d] <= maxSum) { temp.push_back(1); temp.push_back(board[d]); temp.push_back(board[d]); legalMoves.push_back(temp); temp.clear(); }
// finds all the double moves if ((d + 1) < board.size() ) { for (unsigned int n = (d + 1); n < board.size(); ++n) { if (board[d] + board[n] <= maxSum) { temp.push_back(2); temp.push_back(board[d]); temp.push_back(board[n]); legalMoves.push_back(temp); temp.clear(); } } } } }
I still feel like it can be done better recursively, but so far my efforts always end up with duplicate numbers and then trying to track for duplicate numbers which makes me think the non-recursive approach might end up performing just as well in the end. If you're only looking for subsets of size one or two, then the iterative solution is probably the best. If you insist on using a recursive solution, then here's something I threw together in a few minutes that does not produce double results:
#include <cstdio> #include <vector>
typedef std::vector<int> vi; typedef std::vector<vi> vvi;
// d: depth // k: current number // n: end of set (1,..,n) // m: max sum // cs: current sum // cur: current answer // res: resultset void dfs(int d, int k, int n, int m, int cs, vi &cur, vvi &res) { if (d==2) { res.push_back(cur); return; }
if (k > m) return;
if (d==1) res.push_back(cur);
for(int i=k;i<=n;++i) { cs+=i; if (cs > m) return; cur.push_back(i); dfs(d+1, k+1, n, m, cs, cur, res); cs-=i; cur.pop_back(); } }
int main() { vvi res; vi cur;
for(int i=4;i<20;++i) { res.clear(); cur.clear(); printf("Solution for N=%d and M=%d\n", i, i+5); dfs(0, 1, i, i+5, 0, cur, res); for(int j=0;j<res.size();++j) { for(int k=0;k<res[j].size();++k) { printf("%d ", res[j][k]); } printf("\n"); } printf("\n"); }
return 0; }
EDIT: I just read up a few posts. This is probably useless to you. =[
|
i miss old school programing. gold old c++ none of this evil java stuff.
|
I miss C# Taking a class that demands I use C++ this year has been painful lol. I've taken C++ previously and I'm better at it now, but still find it painful to use. So much more typing required for all the programming I want to do. Meh. I know its a religious debate topic... so... yeah... I had to learn C# at my last job and loved coding with it.
|
1019 Posts
Hey guys, I'm trying to print a 52 x 72 rectangular grid using character X's and two dimensional arrays, and I'm not sure what I'm doing wrong here. Can you see what is wrong? Thanks
const int row = 52; const int column = 72;
void printRace(const char grid[row][column]) //prints 52 by 72 grid { for (int i = 0; i < row; i++) { for (int j = 0; j < column; j++) { cout << grid[i][j]; } cout << endl; } }
void initRace(const char track[row][column]) { for (int i = 0; i == 0 && i == 51; i++) //top and bottom boundary { for (int j = 0; j < 72; j++) { track[i][j] = 'X'; // <------------- COMPUTER SAYS ERROR ON THIS LINE } }
for (int i = 1; i == 50; i++) //left and right boundary { for (int j = 0; j == 0 && j == 71; j++) { track[i][j] = 'X'; // <------------- COMPUTER SAYS ERROR ON THIS LINE } } }
int main() {
printRace(row, column); initRace(row, column);
return 0;
}
|
On November 05 2012 08:51 white_horse wrote: void initRace(const char track[row][column]) <--- look here { ... track[i][j] = 'X'; // <------------- COMPUTER SAYS ERROR ON THIS LINE ... track[i][j] = 'X'; // <------------- COMPUTER SAYS ERROR ON THIS LINE ... }
also an error: printRace(row, column); initRace(row, column);
Read the lines i left over very carefully and you should notice the problem.
|
On November 05 2012 08:51 white_horse wrote:initRace does so not do what you want it to do. There is no need to nest the for loops!
void initRace(const char track[row][column]) { for (int i = 0; i == 0 && i == 51; i++) //top and bottom boundary { for (int j = 0; j < 72; j++) { track[i][j] = 'X'; // <------------- COMPUTER SAYS ERROR ON THIS LINE } }
....
}
I would try something like void initRace(char track[row][column]) { for (int j = 0; j < 72; j++) { track[0][j] = 'X'; track[51][j] = 'X'; } ....
}
actually 2 errors, wrong parameters and you print before you init
int main() {
printRace(row, column); initRace(row, column);
return 0;
}
for (int i = 0; i == 0 && i == 51; i++) The for loop runs as long as i equals 0 and i equals 51, at the same time, not either one.
if you would use:
for (int i = 0; i == 0 || i == 51; i++) The loop would check if i is 0 or 51, it would run 1 time, while i == 0, after that i would be 1 and the loop would end.
You could however:
for (int i = 0; i == 0 || i == 51; i+51) but pls don'T. ;D
|
|
|
|