Robot Game in C ++ – Code Review Stack Exchange

I have a very simple "game" in which a robot is placed on a small 5×5 board and given orders. At the beginning, the robot must be placed on the board, then you can command it to move or to turn left and right. I tried to use object-oriented concepts, but this was not a requirement for my job. I think I did a good job and I would like to know what I did wrong.

Here are a few "requirements" for me:

  1. The command "place" assumes an x, y position and a direction or NORTH, EAST, SOUTH or WEST.
  2. Other commands may only be executed when the robot has been placed
  3. Move moves the robot forward by 1 in the direction in which it is located
    across from.
  4. LEFT and RIGHT turn the robot in their respective directions
  5. REPORT prints the current position and the viewing direction of the
  6. Place is a valid command, even if it has already been placed
  7. Inputs that cause the robot to fall off the board must be
    rejected or ignored
  8. Invalid or "junk" entries are to be ignored
  9. The robot takes commands in plain text, the robot must accept them
    Write an SMS and follow the instructions if they are valid

Example input / output:

Output: 0.3, WEST

and here is my robot.cpp

#include "robot.h"
#include "tabletop.h"
#include "helpers.h"

Namespace ToyRobot
// Used as an interface to provide statements as text
bool Robot :: command (std :: string statement)
std :: istringstream iss (statement);
std :: vector Token {std :: istream_iterator{iss}, std :: istream_iterator{}};

if (this-> commandList.count (token[0])> 0) // is the first token a valid command?
// command is valid
if (tokens[0] == "PLACE")
{// check if there are valid arguments
if (tokens.size () <2)
std :: cout << "Error! Not enough arguments for 'PLACE'n";
                    return false;
                        uint8_t arg1 = std::stoi(split(tokens[1], ",")[0]);
                        uint8_t arg2 = std::stoi(split(tokens[1], ",")[1]);
                        std::string arg3 = split(tokens[1], ",")[2];
                        this->place (arg1, arg2, arg3);
Catch (...)
return it incorrectly;

return true;
otherwise if[0] == "MOVE")
this-> move ();
otherwise if[0] == "LEFT" || token[0] == "RIGHT")
this-> turn (token[0]);
otherwise if[0] == "REPORT")
this-> printStatus ();

return true;
return it incorrectly;

// checks if a certain position is valid (used only by other methods)
bool Robot :: isValidPosition (uint8_tx, uint8_t y)
if (x < 0 || x > TABLETOP_MAX_X || y < 0 || y > TABLETOP_MAX_Y)
return it incorrectly;
return true;

// Places the robot ignoring invalid positions
bool Robot :: place (uint8_t x_place_pos, uint8_t_y_place_pos, std :: string facingDirection)
if (x_place_pos < 0 || x_place_pos > TABLETOP_MAX_X || y_place_pos < 0 || y_place_pos > TABLETOP_MAX_Y)
return it incorrectly;

if (this-> facingDirections.count (facingDirection) == 0) // check if the specified line of sight is valid
return it incorrectly;

this-> x_pos = x_place_pos;
this-> y_pos = y_place_pos;

this-> facingDirection = this-> facingDirections[facingDirection];

this-> placement = true;
return true;

// moves the robot forward by one, ignoring invalid moves
bool Robot :: move ()
if (this-> placed)
uint8_t sim_x = this-> x_pos;
uint8_t sim_y = this-> y_pos;

// simulate movement
if (facingDirection == 0)
sim_y + = 1;
otherwise if (facingDirection == 1)
sim_x + = 1;
otherwise if (facingDirection == 2)
sim_y - = 1;
otherwise if (facingDirection == 3)
sim_x - = 1;

if (isValidPosition (sim_x, sim_y)) // If it was valid, put and return true
this-> x_pos = sim_x;
this-> y_pos = sim_y;
return true;
otherwise // invalid train (out of bounds)
return it incorrectly;
otherwise // not placed
return it incorrectly;

// turns the robot in a given direction
bool Robot :: rotate (std :: string direction)
if (this-> placed)
uint8_t sim_direction = this-> facingDirection;

if (direction == "LEFT")
sim_direction = (sim_direction + 3)% 4; //To turn left
otherwise if (direction == "RIGHT")
sim_direction = (sim_direction + 1)% 4; // turn right
return it incorrectly; //Invalid Input

this-> facingDirection = sim_direction;
return true;
otherwise // not placed
return it incorrectly;

void Robot :: printStatus ()
if (this-> placed)
std :: cout << int(this->x_pos) << & # 39 ;, & # 39; << int(this->y_pos) << & # 39 ;, & # 39; << (this->reverse directions[this->facingDirection]) << " n";
std :: cout << "Robot is not yet placed on the tabletop!  n";


#pragma once

#include "stdafx.h"

Namespace ToyRobot
Class robot
Bool placed = wrong;
uint8_t x_pos = NULL;
uint8_t y_pos = NULL;
uint8_t facingDirection = NULL;

const std :: unordered_set commandList = {"PLACE", "MOVE", "LEFT", "RIGHT", "REPORT"};

std :: unordered_map  mounts
= {{"NORTH", 0}, {"EAST", 1},
{"SOUTH", 2}, {"WEST", 3}};

std :: unordered_map  reverse directions
= {{0, "NORTH"}, {1, "EAST"},
{2, "SOUTH"}, {3, "WEST"}};

bool isValidPosition (uint8_t, uint8_t);
Robot () // constructor

Command bool (std :: string);
bool place (uint8_t, uint8_t, std :: string);
bool move ();
bool rotate (std :: string);
void printStatus ();


#include "stdafx.h"
#include "helpers.h"

// Python's "split" function, implemented in C ++. Returns a vector of split std :: strings by a specified delimiter
std :: vector split (const std :: string & in, const std :: string & delim)
using std :: string;
using std :: vector;

string :: size_type start = in.find_first_not_of (delim), end = 0;

vector out;
while (start! = in.npos)
end = in.find_first_of (delim, start);
if (end == in.npos)
out.push_back (in.substr (start));
out.push_back (in.substr (start, end - start));
start = in.find_first_not_of (delim, end);
to return;


#pragma once

#include "stdafx.h"

std :: vector split (const std :: string & in, const std :: string & delim);

tabletop.h (there is no tabletop.cpp, since there is no need for it)

#pragma once

#include "stdafx.h"

constexpr auto TABLETOP_MAX_X = 4;
constexpr auto TABLETOP_MAX_Y = 4;

// 0.0 is the southwestern corner
// Tabletop is never used, but it's here if needed
Class tabletop
const uint8_t x_len = TABLETOP_MAX_X;
const uint8_t y_len = TABLETOP_MAX_Y;

and finally my stdafx.h

#pragma once


My robot head and my implementation are in a namespace because they are supposed to be compiled into a library.

What is my project structure? Many Thanks

Design Review: Randomly generated primary keys in the database

In my web application, entities have unique IDs, and for some entity types (for example, user, order, and so on), user IDs are visible through URLs. MySQL is used to store the entities.

Using the auto-increment integer as the primary key is easy and convenient. However, if made available in the URL, users can estimate the entity quantity or rate by using the IDs (German Tank Problem). We may want to avoid this.

After reading many posts on the subject, I know of several approaches to mitigate disclosure of information, such as: Generate random IDs from the app, use UUIDs, encrypt / hashes the last insert ID, and so on.

But finally, I found my approach.

First, create a list of unique integers and preload them into the database.

Since I will not have billions of records, I could create a large sequential list and mix them in memory.

Table for storing the integers would be:


The ENTITY_ID The column is assigned the integer value.

Second, prepare the entity table and a counter table:

) ENGINE = InnoDB;

entity_name CHAR (30) PRIMARY KEY,

INSERT INTO id_counter (entity_name) VALUES (& # 39; entity1 & # 39;);

Finally, use a "BEFORE INSERT" trigger to retrieve an ID from the entity1_id Table, and increase the ID counter.

The counter is used to track the used IDs in entity1_id Table. think of entity1_id as a card, entity1_id[counter] Specifies the next entity ID.

Here is the trigger:



SET cnt = (SELECT counter FROM id_counter WHERE entity_name = & lt; entity1 & # 39; FOR UPDATE);

SET eid = (SELECT entity_id FROM entity1_id WHERE id = cnt);
IF (oath is NULL) THEN
SET @errMsg = CONCAT ("Table` entity1_id` has no line with id =", cnt);
SIGNAL SQLSTATE & # 39; 45000 & # 39; SET MESSAGE_TEXT = @ errMsg;

SET = oath;
UPDATE id_counter SET counter = counter + 1 WHERE entity_name = & # 39; entity1 & # 39 ;;


I just tested this approach when I put it in the Unit 1 Table, if I would If no ID is given, an ID is taken from the entity1_id Table; If an ID is specified, it will be used entity1_id and id_counter is not visited; if I would is not specified and there are not enough IDs in entity1_idthe error is reported.

I think this approach is good for me:

  1. I get randomly generated IDs
  2. I can decide which IDs to use
  3. It is not slow

In my opinion, this approach has three disadvantages:

  1. It is not an easy solution
  2. the risk of no longer having ID cards
  3. additional space for the pre-generated IDs
  • Am I doing something wrong?
  • Are there any other risks that I'm not aware of?

Web crawler – website audit / review of existing content

I have been asked to redesign an existing website, before I do so I need to conduct an audit or review the existing content. I want to know how many pages, documents, and so on, so that I can specify an exact completion time for the project.

I've tried Screaming Frog, but I seem to get many duplicate pages. I know there are at least 500 pages, so I'm limited to the free version of some tools.

Is there any other option or suggested alternative than doing this manually?

Smart Contract Review Services – Cryptocurrencies Corner

An intelligent contract is coded with conditions that must be met in order to execute yourself. It has to be perfect and flawless before it comes into force, as it is permanent and can not be changed. For this reason, the consideration of the smart contract is crucial. At Blockchain App Factory, a leader in Blockchain, you can take advantage of the best contract review services.

100% honest review of Incero LLC

Hello everybody.

I'm here to give a nice review of, its services and staff.

In recent years, I've used Incero for some launch services, such as some dedicated servers that enable me to be where I now have more servers than I do now. During my tenure at Incero, I had a variety of servers, from simple E3 servers with a few 1 TB hard drives to individual 2.10 GHz E5-2620 v2 servers, 128 GB RAM and 4 x 3 TB. Strangely enough, the only problem I've ever had and obviously can not control was a dying drive. They replaced one of the 3 TB drives with a 4 TB drive. They replaced it and I think it may have been equity only, but I never asked for it. This server took a long time, hundreds of clients were loaded on it, and I was constantly on the network. We also had a bandwidth limit of 50 TB, which I believe we never did. So you have a lot of bandwidth for a server that costs me $ 93. I mean, if we needed more, pricing for adding more is fantastic and unbeatable.

So our hardware was perfect, just 1 hard drive failure with their servers all the time, and that hard drive fell out before I installed clients on it, so I can not complain. Luckily, they quickly replaced them. My wait was a maximum of a few minutes, until I got back to IPMI and installed Linux.

Her staff now, her staff of 1 (from all tickets, I just got Ryan, I think), her 1 staff took care of everything for me when I had to do things. He was punctual, fast, very friendly and has a great attitude, even if you read through the tickets. Of all this, I can only praise his work as a technician on site, who does all the work. He is super friendly again, has taken care of and even made sure that everything is going well. He's a great … and I mean, Hivelocity is a BIG win. If anything, he has to take care of everything, because every data center would be lucky enough to have a dedicated employee like him. So Hivelocity, I'd better hear that he cares

The last thing that impressed me was the operating time. I do not think my servers were down during my time at Incero (unless I was guilty or the 1 hard drive failed during Linux installation). I did not even have big latency spikes, weird issues where bgp passed your data incoherently. I honestly had perfect hours of operation. I'm sure if I ever had an uptime timer for it, I'd put it here and display the perfect 100% uptime (unless I'm an idiot and conflict with a production server). Your network is top-notch, alerting you quickly to any misuse of IP and spikes in traffic, and ensuring that your server is not hit hard.

I will return to Incero once a day to settle there as a second location so I can safely split my setup. Incero is the second location at the top of my colocation list. I can only say good things about these guys. Please select Incero if you want to set up a location in Dallas, Texas, or any location you provide. If I could do it all over again, I would still choose Incero as I did. It was a damn good time with them. We just quit our last server with them because we have our own hardware. But I know I'll work with them soon enough if we need more racks in Dallas.


Please, go with Incero. Best company I've worked with for years. Perfect uptime (except when I'm stupid), great staff! Your service is the best in Dallas, hell, maybe across Texas.

[BOUNTY] Lukki Exchange Bounty Review: A $ 125, $ 50 and $ 25 Chance on Cryptocurrencies Corner

Paysafecard vouchers can be redeemed immediately: for PayPal, Skrill, Perfect Money, Webmoney, Bitcoin, Litecoin, Ethereum, Dash.
Paysafecard Vouchers and Bitcoin / Litecoin / Ethereum / Dash Swap Instantly: We accept prepay vouchers from Paysafecard for digital currency exchange on PayPal, Perfect Money, Skrill, Webmoney, and Cryptocurrency Bitcoin, Litecoin, Ethereum, Dash. On our website, you can convert the Paysafecard codes into electronic money at any time.
We sell digital currency with Paysafecard 24 hours a day, 7 days a week.
We accept Paysafecard from the following countries: United Kingdom, Australia, Belgium, Canada, Czech Republic, Denmark, Germany, Ireland, Spain, France, Croatia, Italy, Latvia / Latvia, Lietuva / Lithuania, Luxembourg / Luxembourg, Magyarország / Hungary, Malta , Nederland / Netherlands, Norway / Norway, Austria / Austria, Polska / Poland, Portugal, Romania / Romania, Switzerland / Switzerland, Slovenija / Slovenia, Slovensko / Slovakia, Switzerland / Finland, Sweden / USA, Sweden / Cyprus, Kuwait, Mexico , United Arab Emirates, Saudi Arabia, Egypt / Kuwait.
You can redeem immediately: Paysafecard EUR, Paysafecard GBP (British Pound Sterling), Paysafecard USD (US Dollar), Paysafecard AUD (Australian Dollar), Paysafecard CAD (Canadian Dollar), Paysafecard CHF (Swiss Franc), Paysafecard NZD (New Zealand) Paysafecard CZK (Czech Crown), Paysafecard DKK (Danish Krone), Paysafecard HUF (Hungarian Forint), Paysafecard NOK (Norwegian Krone), Paysafecard PLN (Polish Zloty), Paysafecard RON (Romanian Leu), Paysafecard SEK (Swedish Krona)), Paysafecard KWD (Kuwaiti Dinar), Paysafecard MXN (Mexican Peso).
Paysafecard to PayPal GBP, PayPal EUR, PayPal USD
Paysafecard to Perfect Money EUR, Perfect Money USD
Paysafecard to Skrill EUR, Skrill USD
Paysafecard to Webmoney WME, Webmoney WMZ
Paysafecard on Cryptocurrency Bitcoin, Litecoin, Ethereum, Dash
We accept at least: 20 Paysafecard GBP / EUR / USD / KWD, 25 Paysafecard AUD / CAD / CHF / NZD, 100 Paysafecard PLN / RON, 200 Paysafecard DKK / HRK / NOK / SEK, 500 Paysafecard CZK, 5000 Paysafecard HUF.
Now you can instantly exchange or transfer your money with our lowest fees from Bitcoin Litecoin, Ethereum, Dash and Paysafecard.
Want to load your PayPal, Perfect Money, Skrill, Webmoney, Bitcoin, Litecoin, Dash, or Ethereum account?
You can use the Paysafecard voucher to top up your PayPal, Perfect Money, Skrill, Webmoney, Bitcoin, Litecoin, Dash or Ethereum account / Wallet.
Immediate exchange of prepaid vouchers Paysafecard and crypto-currency Bitcoin, Litecoin, Ethereum, Dash against international payment systems for electronic money.
We accept Bitcoin cryptocurrency for the exchange into digital currencies of the payment systems PayPal, Perfect Money, Skrill, Webmoney. On our website you can convert Bitcoin into electronic money at any time. We offer the best exchange rates Bitcoin.
We sell digital currency through Bitcoin 24 hours a day, 7 days a week.
Do you want to top up your PayPal, Perfect Money, Skrill, or Webmoney account?
You can top up your PayPal, Perfect Money, Skrill and Webmoney account with Bitcoin Crypto.
Bitcoin to PayPal GBP, PayPal EUR, PayPal USD
Bitcoin to Perfect Money EUR, Perfect Money USD
Bitcoin to Skrill EUR, Skrill USD
Bitcoin to Webmoney WME, Webmoney WMZ
We accept at least 0.005 Bitcoin.
You can immediately charge PayPal with Bitcoin (BTC), Perfect Money with Bitcoin (BTC), Skrill via Bitcoin (BTC) and Webmoney via Bitcoin (BTC). You can buy PayPal with Bitcoin, Skrill (Moneybookers) with Bitcoin, Perfect Money with Bitcoin and Webmoney with Bitcoin.
We accept Litecoin cryptocurrency for exchange into digital currencies of payment systems PayPal, Perfect Money, Skrill, Webmoney. On our website, you can convert Litecoin into electronic money at any time. We offer the best exchange rates Litecoin.
We sell digital currency with Litecoin 24 hours a day, 7 days a week.
Do you want to top up your PayPal, Perfect Money, Skrill, or Webmoney account?
You can top up your PayPal, Perfect Money, Skrill and Webmoney account with Litecoin Crypto.
Litecoin to PayPal GBP, PayPal EUR, PayPal USD
Litecoin to Perfect Money EUR, Perfect Money USD
Litecoin to Skrill EUR, Skrill USD
Litecoin to Webmoney WME, Webmoney WMZ
We accept at least 0.3 Litecoin.
You can immediately charge PayPal via Litecoin (LTC), Perfect Money via Litecoin (LTC), Skrill via Litecoin (LTC) and Webmoney via Litecoin (LTC). You can buy PayPal with Litecoin, Skrill (Moneybookers) with Litecoin, Perfect Money with Litecoin and Webmoney with Litecoin.

We accept the cryptocurrency Ethereum (ETH) for the exchange into digital currencies of the payment systems PayPal, Perfect Money, Skrill, Webmoney. On our website, you can convert the Ethereum into electronic money at any time. We offer the best exchange rates Ethereum.
We sell digital currency with Ethereum 24 hours a day, 7 days a week.
Do you want to top up your PayPal, Perfect Money, Skrill, or Webmoney account?
You can use Ethereum Crypto to charge your PayPal, Perfect Money, Skrill and Webmoney account.
Transfer to PayPal GBP, PayPal EUR, PayPal USD
The Äthereum to Perfect Money EUR, Perfect Money USD
Ethereum to Skrill EUR, Skrill USD
Ethereum to Webmoney WME, Webmoney WMZ
We accept minimum: 0.1 Ethereum.
You can immediately charge PayPal via Ethereum (ETH), Perfect Money via Ethereum (ETH), Skrill via Ethereum (ETH) and Webmoney via Ethereum (ETH). You can buy PayPal with Ethereum, Skrill (Moneybookers) with Ethereum, Perfect Money with Ethereum and Webmoney with Ethereum.

We accept Dash cryptocurrency for the exchange into digital currencies of the payment systems PayPal, Perfect Money, Skrill, Webmoney. On our website, you can convert the Dash into electronic money at any time. We offer the best exchange rates Dash.
We sell digital currency through Dash 24 hours a day, 7 days a week.
Do you want to top up your PayPal, Perfect Money, Skrill, or Webmoney account?
You can top up your PayPal, Perfect Money, Skrill and Webmoney account through Dash Crypto.
Cash on PayPal GBP, PayPal EUR, PayPal USD
Stroke for the perfect money EUR, perfect money USD
Stroke to Skrill EUR, Skrill USD
Dash to Webmoney WME, Webmoney WMZ
We accept at least 0.3 hyphens (DASH).
You can instantly load PayPal through Dash (DASH), Perfect Money via Dash (DASH), Skrill via Dash (DASH), Webmoney via Dash (DASH). You can buy PayPal with Dash, Skrill (Moneybookers) with Dash, Perfect Money with Dash, and Webmoney with Dash.
We offer services of Auto Exchange Paysafecard, informative and other types of services in the field of electronic commerce and private systems of Internet payments. We are certified partners of the payment systems Paypal, Webmoney, Perfect Money, Skrill.

We offer our customers the most favorable warranty conditions. Beneficial to work with us! We always offer our customers the cheapest exchange rate.

There are many different e-currency exchangers around the world that provide similar services as we do. However, we believe that we have properties that distinguish us from the others:
– We are the fastest. Many stock traders use the same system to exchange their customers' money. We have rebuilt our own system from scratch. We have established relationships with electronic currency providers to enable an innovative rate of exchange.
– Today we offer the lowest exchange rates. Our agents work hard every day to make sure that our customers receive only the best deals to exchange their money. We find it unfair for stock market operators to charge high stock market fees while service costs are relatively low.
A bit of history of our business, we have been working in manual mode, sharing different users in various forums and the most well-known covered areas of the internet. Our guarantee is more than 1,000 dedicated successful exchanges and reviews of our customers, we are pleased.

Our company is a team of young and smart people, and we believe that in the online business, the most important thing is being open and negotiable. We are always open to new ventures and partnerships as the Internet changes daily and the only way to consolidate in the marketplace is to innovate. Many exchangers emphasize their reliability.

We have been working with Exchange Paysafecard for more than 9 years – you have a good experience. There is a lot of feedback from our loyal customers.

We believe that this does not even have to be mentioned, as every company has to be fair and comply with the law. However, the online business is a place full of fraudulent people who seek to harm other people or businesses. That is why we regularly invest in the security of our website and always carry out a review of our customers. Reliability is a virtue that can easily be lost, but we are ready to do anything to ensure our stability and credibility.

We give gifts and bonuses to all regular customers, which are paid in exchange.

Our service is constantly evolving and soon we will offer you further e-commerce services. If you have any questions, we are always at your disposal. Please contact us. We are always ready to improve the service exchange – if you help us!


Review Torrent Leecher Website: | WJunktion

Hi Guys,

I have developed a website for torrent leecher.

You can delete torrents up to 5GB / file and subscribe to your email address for a notification when your Torrent-Leech is already over.


  1. Blutegelbach up to 5 GB/File.
  2. You can convert your magnet link into a torrent file.
  3. You can subscribe to your e-mail address to receive a notification when your leech is already done. (Your email has been encrypted and never shared with the public)
  4. The torrent was mirrored to store host sites like Uptobox, Openload, and so on.

The website:
Magnet to Torrent:

I would appreciate your feedback on design and features. Many Thanks!

NEW – Review: Scam or Legit? | Proxies-free

Great refund
2 days
Minimum: 0.0002 BTC
Max: 0.01 BTC

Koi Ueno
3 days
Minimum: 0.001 BTC
Max: 0.02 BTC

Trinity Bull
4 days
Minimum: 0.0005 BTC
Max: 0.1 BTC

4 days
Minimum: 0.002 BTC
Max: 0.2 BTC

Seven path
5 days
Minimum: 0.0002 BTC
Max: 0.2 BTC

Fertility Samar
5 days
Minimum: 0.005 BTC
Max: 0.3 BTC

White elephant
6 days
Minimum: 0.0002 BTC
Max: 0.5 BTC

Jade Treasury
6 days
Minimum: 0.01 BTC
Max: 2 BTC

PS. The same applies to other Bitcoin investments such as prospercore, bitcoinsquare, stratusBTC and Bitcoinsense.

Register here: