void CmdMove(CORE_DATA *cd) { USER_DATA *ud = UD(cd); // the game hasnt started if (ud->in_progress == false) { Reply("The game has not yet begun"); return; } // check for correct arg count if (cd->cmd_argc != 2) { ReplyFmt("Usage: !move Coord,Coord"); ReplyFmt("Example: !move e2,e4"); return; } // make sure the player is playing if (IsPlaying(ud, cd->cmd_name) == false) { Reply("You are not playing in this match"); return; } // replies to players in-game are via arena // check whos turn it is if (GetColor(ud, cd->cmd_name) != ud->to_move) { ArenaMessage("It is not your move"); return; } // parse argument char xstr[3]; char ystr[3]; DelimArgs(xstr, 3, cd->cmd_argv[1], 0, ',', false); DelimArgs(ystr, 3, cd->cmd_argv[1], 1, ',', false); int x1, y1, x2, y2; if (ParseCoords(xstr, &x1, &y1) == true && ParseCoords(ystr, &x2, &y2) == true) { char *err = TryMove(ud, ud->to_move, x1, y1, x2, y2); if (err == NULL && ud->in_progress == true) { // successful moves are announced in TryMove() ud->to_move = GetOppositeColor(ud->to_move); LvzToMove(ud->to_move, NULL); ArenaMessageFmt("%s (%s) to Move", GetPlayerName(ud, ud->to_move), GetColorText(ud->to_move)); } else if (ud->in_progress == true) { ArenaMessageFmt("Couldn't move: %s", err); } } else { ArenaMessageFmt("Invalid coordinates"); } }
static void SetPieceAt(BOARD b, char *loc, COLOR c, TYPE t) { int x, y; bool rv = ParseCoords(loc, &x, &y); // this is a utility function so asserting here is okay // since the argument isnt user input assert (rv == true); SetPieceAt(b, x, y, c, t); }
const bool CLevel::ParseItem(const std::string& str, int& x, int& y, ITEM_TYPE& type, std::vector<std::string>& params) { auto pos = str.find( "=" ); if( pos == std::string::npos ) return false; if( !ParseCoords( str.substr( 0, pos ), x, y ) ) return false; auto itemdef = str.substr(pos + 1); pos = itemdef.find("("); auto end = itemdef.find(")"); if(pos == std::string::npos || end == std::string::npos) return false; type = ::ParseItem(itemdef.substr(0, pos)); SplitString( itemdef.substr(pos + 1, end - pos - 1), ",", params ); return true; }