HiveBrain v1.2.0
Get Started
← Back to all entries
patterncppModerate

'Evolutionary AI' implementation

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
implementationevolutionarystackoverflow

Problem

For the code sample that I am asked to submit with most of my job applications (usually Gameplay Programmer), I created this console application in which I attempt to figure out what is the best loadout for a mech to win a match within the simple turn-based combat system that I came up with. Since I will submit this as a code sample, it is important to me that it works and looks the best, and I would really appreciate all the input that you could give me.

I would like to mention that I already posted this sometime last summer, but since then I reworked it considerably (mostly because I studied up on C++11), so I hope it's OK to resubmit.

What I'm interested in is really everything that comes to your mind when you see this — about the design, implementation, presentation, naming, or really anything that you think is important.

In particular, am I really taking advantage of all the C+11 concepts that I can, and am I using them in a correct manner?

The code as well as the rules are available online: http://www.mz1net.com/code-sample

(UPDATE: I've updated the online version with the edits that I made based on Jamal's response.)

This is Main.cpp - please see the 'MechArena.cpp' and 'MechArena.h' online:

```
#include
#include
#include
#include

#include "MechArena.h"

// ======================================================================================

void init()
{
srand((int)time(0));

std::cout > size)
{
if (size % 2 > 0)
{
std::cout 0)
{
// Make sure that we were not asked to display more
// mechs than how many there are in the entire population.
size_t populationSize = population.getSize();
if (displayWinners > populationSize)
{
std::cout 1)? " MECHS" : " MECH") << " IN THE POPULATION: " << std::endl;
std::cout << "--------------------------------------" << std::endl;
std::cout <

Solution

There's something which worries me about using this as a sample for a job application: which is that it contains no virtual methods and no subclasses.

No matter how clearly-written your code may be, it doesn't demonstrate an understanding of inheritance: which (I don't know) might be an important criterion in a job application.

If this is valid criticism, perhaps change the game design so as to use inheritance in a natural way.

One (advanced) way to do this might be to have the type of weapon have a different effect depending on the type of armour (as in a game or "rock, paper, sissors", the effect of the weapon varies depending on the target). I'm thinking of this as an example, because a "implementing a video game" is the canonical example used to teach an 'advanced' technique called double-dispatch. Working that implementation (if game-rule have a natural need for that implementation technique) into your sample might impress someone reviewing resumes/samples.

People might also like to see a knowledge of (i.e. appropriate use of some) common design patterns.

My apologies for this advice: it's based on a cynical guess at the type of code which some interviewers may be looking for.

Again based on experience with interview questions, they might also like to know:

  • How do/did you test this?



  • Have you thought about how to extend/maintain it various ways? I mean, add new types of feature: a GUI; playing it over the network; persisting (saving and restoring) game-state; making it a 0-player, 1-player, 2-player, or many-player game; etc.

Context

StackExchange Code Review Q#39097, answer score: 10

Revisions (0)

No revisions yet.