blob_id stringlengths 40 40 | language stringclasses 1
value | repo_name stringlengths 5 117 | path stringlengths 3 268 | src_encoding stringclasses 34
values | length_bytes int64 6 4.23M | score float64 2.52 5.19 | int_score int64 3 5 | detected_licenses listlengths 0 85 | license_type stringclasses 2
values | text stringlengths 13 4.23M | download_success bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|
c949c28b0a9b9b1f2636f767df0a29bd1111f646 | C++ | danleechina/Leetcode | /archive1/55.cpp | UTF-8 | 728 | 2.640625 | 3 | [] | no_license | #include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
class Solution {
public:
bool canJump(vector<int>& nums) {
if (nums.size() == 0) return false;
if (nums.size() == 1) return true;
int currentMostFarDistant = nums[0];
int currentCheckPlace = 0;
for (int i = currentCheckPlace; i <= currentMostFarDistant; i ++) {
int iMostFarDistant = nums[i] + i;
currentMostFarDistant = max(currentMostFarDistant, iMostFarDistant);
if (currentMostFarDistant >= nums.size() - 1) return true;
}
return currentMostFarDistant >= nums.size() - 1;
}
}; | true |
7dcf85a0e5ff27fe06d23cfe3c00166e708cd3ea | C++ | TheGhostHuCodes/CoreCpp | /CoreCpp5OfN.cpp | UTF-8 | 1,188 | 3.78125 | 4 | [] | no_license | #include <string>
#include <ostream>
#include <iostream>
using namespace std;
// Primary template.
template <typename T> struct Kitty {
static void Meow() { cout << "Kitty<T>::Meow()!" << endl; }
};
// Full or Explicit specializaiton.
template <> struct Kitty<const char*> {
static void Meow() { cout << "Kitty<const char*>() yay!" << endl; }
};
// Partial specializaiton.
template <typename X> struct Kitty<X*> {
static void Meow() { cout << "Kitty<X*>() yay!" << endl; }
};
template <typename T> void meow(T) { cout << "meow<T>()!" << endl; }
// Overloaded template, there is no such thing as a partially specialized
// function template. There are only partially specialized class templates.
template <typename X> void meow(X*) {
cout << "meow(X*) is an overloaded template!" << endl;
}
template <> void meow(long) {
cout << "meow(long) is an explicit/full specialization!" << endl;
}
// void meow(long) {
// cout << "meow(long) is an ordinary function!" << endl;
//}
int main() {
Kitty<int>::Meow();
Kitty<const char*>::Meow();
Kitty<double*>::Meow();
meow(1729);
meow(0L);
meow(static_cast<double*>(nullptr));
return 0;
}
| true |
dd950843daefebe77d86521ea961562666c60f65 | C++ | xubingyue/GP | /httpserver/comm/Util/Helper.cpp | UTF-8 | 6,583 | 2.8125 | 3 | [] | no_license | //
// Created by new on 2016/11/8.
//
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <arpa/inet.h>
#include "Helper.h"
#include "StrFunc.h"
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/if_ether.h>
string Helper::filterInput(string str)
{
if (str.empty()) return "";
// 需要替换的特殊字符
string ret;
char specialStr[41] = {'\\', '\'', '"', '`', '&', '/', '<', '>', '\x7f'};
for (int i = 0; i < 32; i++ )
specialStr[9+i] = (char)i;
for (int i = 0; i < str.length(); i++) {
char c = str.at(i);
int j;
for (j=0;j<sizeof(specialStr);j++)
if (specialStr[j] == c)
break;
if (j == sizeof(specialStr)) {
ret.push_back(c);
}
}
return ret;
}
int Helper::strtotime(string date)
{
struct tm t;
unsigned long time;
sscanf(date.c_str(),"%d-%d-%d %d:%d:%d",&t.tm_year,&t.tm_mon,&t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec);
t.tm_year-=1900;
t.tm_mon-=1;
time=mktime(&t); //转换
return time;
}
vector<string> Helper::explode(const char * str, const char * sep)
{
char *srcstr = strdup(str);
vector<string> result;
char *saveptr = NULL;
char *p = strtok_r(srcstr, sep, &saveptr);
while (p) {
result.push_back(p);
p = strtok_r(NULL, sep, &saveptr);
}
free(srcstr);
return result;
}
string Helper::implode(const char *sep, const vector<string>& strarr)
{
string strRet = "";
for (int i = 0; i < strarr.size(); i++)
{
if (!strRet.empty()) strRet += sep;
strRet += strarr[i];
}
return strRet;
}
std::string Helper::implode( const char* sep, const Json::Value& strarr )
{
std::string strRet = "";
if (strarr.type() == Json::ValueType::objectValue)
{
Json::Value::Members mem = strarr.getMemberNames();
for (Json::Value::Members::iterator iter = mem.begin(); iter != mem.end(); iter++)
{
if (!strRet.empty()) strRet += sep;
strRet += strarr[*iter].asString();
}
}
else if(strarr.type() == Json::ValueType::arrayValue)
{
int nMaxNum = strarr.size();
for (int i = 0 ; i < nMaxNum; i++)
{
strRet += strarr[i].asString();
}
}
return strRet;
}
std::string Helper::implode(const char *sep, const std::vector<int>& vec)
{
std::string str = "";
for (size_t i = 0; i < vec.size(); i++)
{
str = StrFormatA("%s%d%s", str.c_str(), vec[i], sep);
}
//gcc 4.4不支持string::pop_back
str.erase(str.end()-1); //去除尾部的split
return str;
}
string Helper::strtolower(const char* str)
{
string ret = str;
ToLower(ret);
return ret;
}
string Helper::trim(const char *str) {
return TrimStr(str);
}
const char *charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
bool Helper::isUsername(const char *str) {
int len = strlen(str);
if (len < 3 || len > 16)
return false;
while(*str && !strchr(charset, *str))
return false;
return true;
}
long Helper::ip2long(const char *ip) {
return ntohl(inet_addr(ip));
}
std::string Helper::long2ip(long ip)
{
in_addr addr;
addr.s_addr = ip;
char* saddr = inet_ntoa(addr);
if (saddr != NULL)
{
return std::string(saddr);
}
return "";
}
string Helper::replace(const string& str, const string& src, const string& dest)
{
string ret;
string::size_type pos_begin = 0;
string::size_type pos = str.find(src);
while (pos != string::npos)
{
ret.append(str.data() + pos_begin, pos - pos_begin);
ret += dest;
pos_begin = pos + 1;
pos = str.find(src, pos_begin);
}
if (pos_begin < str.length())
{
ret.append(str.begin() + pos_begin, str.end());
}
return ret;
}
int Helper::time2morning() {
time_t now = time(NULL);
struct tm today = *localtime(&now);
double seconds;
today.tm_hour = 0; today.tm_min = 0; today.tm_sec = 0;
seconds = 24*60*60-difftime(now,mktime(&today));
return (int)seconds;
}
std::string Helper::GetPeerMac( int sockFd )
{
struct arpreq arpReq;
struct sockaddr_storage dstadd_in; //注意IPV6
socklen_t len;
memset(&arpReq,0,sizeof(struct arpreq));
memset(&dstadd_in,0,sizeof(struct sockaddr_storage));
if (getpeername(sockFd,(struct sockaddr*)&dstadd_in,&len) < 0) return "";
memcpy(&arpReq.arp_pa,&dstadd_in,sizeof(struct sockaddr_in));
strcpy(arpReq.arp_dev,"eth1");
arpReq.arp_pa.sa_family = dstadd_in.ss_family; //兼容IPV6
if(ioctl(sockFd, SIOCGARP, &arpReq) < 0) return "";
unsigned char * hw_addr = (unsigned char *) arpReq.arp_ha.sa_data;
return StrFormatA("%02x%02x%02x%02x%02x%02x", *hw_addr, *(hw_addr+1), *(hw_addr+2), *(hw_addr+3), *(hw_addr+4), *(hw_addr+5));
}
void unsetUserFiled(Json::Value& jvUser)
{
std::string strUnsetFiled[] = {"bankPWD", "device_no", "ipArr", "mtype", "deviceToken", "aMactivetime", "aMentercount", "aMtime", "aPid", "aVersions", "devicename", "osversion", "nettype",
"vendor", "gameid", "cid", "pid", "ctype", "versions", "mtime", "mstatus", ""};
int i = 0;
while (!strUnsetFiled[i].empty())
{
if (!jvUser[strUnsetFiled[i]].isNull()) jvUser.removeMember(strUnsetFiled[i]);
i++;
}
}
int32_t Helper::getCurMonthTimeStamp()
{
time_t t = time(0); // get time now
struct tm * zeroTm= localtime(&t);
if(zeroTm != NULL)
{
zeroTm->tm_hour = 0;
zeroTm->tm_min = 0;
zeroTm->tm_sec = 0;
zeroTm->tm_mday = 1;
unsigned long long zeroTime = mktime(zeroTm);
return zeroTime;
}
else
{
return 0;
}
}
int32_t Helper::getNextMonthTimeStamp()
{
time_t t = time(0); // get time now
struct tm * zeroTm= localtime(&t);
if(zeroTm != NULL)
{
zeroTm->tm_hour = 0;
zeroTm->tm_min = 0;
zeroTm->tm_sec = 0;
zeroTm->tm_mday = 1;
if(zeroTm->tm_mon == 11)
{
zeroTm->tm_mon = 0;
}
else
{
zeroTm->tm_mon = zeroTm->tm_mon + 1;
}
unsigned long long zeroTime = mktime(zeroTm);
return zeroTime;
}
else
{
return 0;
}
}
std::string Helper::getTimeStampToYearMonthTime(int timestamp)
{
time_t t = timestamp; // get time now
struct tm * zeroTm= localtime(&t);
if(zeroTm != NULL)
{
//mon 是 0~11 所以+1
return StrFormatA("%d.%d",zeroTm->tm_year+1900,zeroTm->tm_mon+1);
}
else
{
return StrFormatA("");
}
}
std::string Helper::getCurYearMonthTime()
{
time_t t = time(0); // get time now
struct tm * zeroTm= localtime(&t);
if(zeroTm != NULL)
{
return StrFormatA("%d.%d",zeroTm->tm_year+1900,zeroTm->tm_mon);
}
else
{
return StrFormatA("");
}
} | true |
3f6e0048c476daaf184153f82038669ab65c2bbb | C++ | westsiderz/OpenCVTrainings | /BP24_HarrisCorner/src/HarrisCorner.cpp | UTF-8 | 2,359 | 3.015625 | 3 | [] | no_license | #include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace cv;
// Apply the Harris Corner Detection operation to an image
void applyHarrisCornerDetection()
{
// Path to the input image
std::string l_pathToInputImage{ "../Resources/car.jpg" };
// Create an object to hold the image data of the first image
Mat l_image;
// Read the image date from a file with no change to color scheme
l_image = imread(l_pathToInputImage, IMREAD_UNCHANGED);
// Check if we have read the first image data correctly
if (!l_image.data)
{
std::cout << "No image data \n";
return;
}
// Convert the image to grayscale
Mat l_imageGrayscale{};
cvtColor(l_image, l_imageGrayscale, COLOR_BGR2GRAY);
// Harris corner detection constants
constexpr int const c_blockSize = 2;
constexpr int const c_apertureSize = 3;
constexpr double const c_kParameter = 0.06;
constexpr int const c_threshold = 120;
// Apply the Harris corner detection
Mat l_outputHarris = Mat::zeros(l_image.size(), CV_32FC1);
cornerHarris(l_imageGrayscale, l_outputHarris, c_blockSize, c_apertureSize, c_kParameter);
// Normalize the result
Mat l_outputHarrisNormalized, l_outputHarrisScaled;
normalize(l_outputHarris, l_outputHarrisNormalized, 0, 255, NORM_MINMAX, CV_32FC1, Mat());
convertScaleAbs(l_outputHarrisNormalized, l_outputHarrisScaled);
// Draw circles around the detected corners
constexpr int const c_radius = 4;
constexpr int const c_lineThickness = 2;
for (int i = 0; i < l_outputHarrisNormalized.rows; i++)
{
for (int j = 0; j < l_outputHarrisNormalized.cols; j++)
{
if ((int)l_outputHarrisNormalized.at<float>(i, j) > c_threshold)
{
circle(l_outputHarrisScaled, Point(j, i), c_radius, Scalar(0, 0, 255), c_lineThickness, LINE_AA);
}
}
}
// Display the input image
namedWindow("Input", WINDOW_NORMAL);
cv::imshow("Input", l_image);
// Display the Harris transform result image
namedWindow("Result Harris Corner Detection", WINDOW_NORMAL);
cv::imshow("Result Harris Corner Detection", l_outputHarrisScaled);
}
int main()
{
applyHarrisCornerDetection();
waitKey(0);
return 0;
}
| true |
1f29a67794addc39c8a83b0905f5c51c876143a0 | C++ | pixel-me/Gets_Started | /Lab14_38_Ashutosh.cc | UTF-8 | 1,034 | 3.515625 | 4 | [] | no_license | #include <cstdio>
#define MAX_NAME 20
using namespace std;
class person{
public:
int id;
char name[MAX_NAME];
};
class student: public person
{
public:
/*There is no specific task described in question of lab number 14 to do in student class, hence I'm keeping it as it is.*/
};
class faculty: public person
{
public:
int salary;
void set_faculty_id(int id)
{
this->id = id;
}
void set_faculty_name(char name[MAX_NAME])
{
this->name = name;
}
};
class grades:public student, public faculty
{
public:
grades();
void display()
{
printf("\n\nName of faculty is: %s\nId of faculty is: %d\n\n",::faculty,::id);
}
~ grades()
{
printf("\n\n*******Object destroying********\n\n");
}
};
int main(int argc, char const *argv[])
{
int id;
char name[MAX_NAME];
grades *obj = new grades();
printf("Set the id of faculty\n");
scanf("%d",&id);
printf("Set the name of faculty\n");
scanf("%[^\n]%*c",&name);
obj->set_faculty_id(id);
obj->set_faculty_name(name);
obj->display();
delete obj;
return 0;
} | true |
0205bb279a3b56b74f673bcd795a50f8f457dd91 | C++ | tasmidur/problemsolving | /levelordertraversal.cpp | UTF-8 | 2,072 | 3.484375 | 3 | [] | no_license | #include<bits/stdc++.h>
#include<queue>
using namespace std;
struct BSTNODE{
int data;
BSTNODE* left;
BSTNODE* right;
} ;
BSTNODE* getNewNode(int data){
BSTNODE* newnode=new BSTNODE();
newnode->data=data;
newnode->left=newnode->right=NULL;
return newnode;
}
BSTNODE* insertdata(BSTNODE* root,int data){
if(root==NULL){
root=getNewNode(data);
return root;
}
else if(root->data>=data){
root->left=insertdata(root->left,data);
} else{
root->right=insertdata(root->right,data);
}
return root;
}
//breathfirst tree traversal
void leveordertraversal(BSTNODE* root){
if(root==NULL){
return;
}
queue<BSTNODE*> q;
q.push(root);
while(!q.empty()){
BSTNODE* current=q.front();
cout<<current->data<<"-->";
if(current->left!=NULL){
q.push(current->left);
}if(current->right!=NULL){
q.push(current->right);
}
q.pop();
}
}
void preodertraversal(BSTNODE* root){
if(root==NULL){
return;
}
cout<<root->data<<"-->";
preodertraversal(root->left);
preodertraversal(root->right);
}
void inodertraversal(BSTNODE* root){
if(root==NULL){
return;
}
inodertraversal(root->left);
cout<<root->data<<"-->";
inodertraversal(root->right);
}
void postodertraversal(BSTNODE* root){
if(root==NULL){
return;
}
postodertraversal(root->left);
postodertraversal(root->right);
cout<<root->data<<"-->";
}
int main(void){
BSTNODE* root=NULL;
root=insertdata(root,15);
root=insertdata(root,10);
root=insertdata(root,20);
root=insertdata(root,25);
root=insertdata(root,5);
root=insertdata(root,30);
root=insertdata(root,2);
root=insertdata(root,7);
cout<<endl<<"level-order"<<endl;
leveordertraversal(root);
cout<<endl<<"pre-order"<<endl;
preodertraversal(root);
cout<<endl<<"In-order"<<endl;
inodertraversal(root);
cout<<endl<<"Post-order"<<endl;
postodertraversal(root);
}
| true |
b9fcf250049c0a4d36ee08b13d2062ee564f6c09 | C++ | hamsham/LightGame | /src/GameSystem.cpp | UTF-8 | 6,327 | 2.84375 | 3 | [
"BSD-2-Clause"
] | permissive | /*
* File: game/ganeSystem.cpp
* Author: Miles Lacey
*
* Created on November 15, 2013, 9:53 PM
*/
#include <chrono> // std::chrono::steady_clock, std::chrono::milliseconds
#include <climits> // UINT_MAX
#include <new> // std::nothrow
#include <utility> // std::move
#include "lightsky/utils/Assertions.h"
#include "lightsky/utils/Log.h"
#include "lightsky/game/GameState.h"
#include "lightsky/game/GameSystem.h"
namespace ls
{
namespace game
{
/*-------------------------------------
SubSystem Constructor
-------------------------------------*/
GameSystem::GameSystem() :
tickTime{0},
prevTime{0},
gameList{}
{}
/*-------------------------------------
SubSystem Move Construction
-------------------------------------*/
GameSystem::GameSystem(GameSystem&& ss) :
tickTime{ss.tickTime},
prevTime{ss.prevTime},
gameList{std::move(ss.gameList)}
{}
/*-------------------------------------
SubSystem Move Operator
-------------------------------------*/
GameSystem& GameSystem::operator=(GameSystem&& ss)
{
tickTime = ss.tickTime;
ss.tickTime = 0;
prevTime = ss.prevTime;
ss.prevTime = 0;
gameList = std::move(ss.gameList);
return *this;
}
/*-------------------------------------
SubSystem Destructor
-------------------------------------*/
GameSystem::~GameSystem()
{
stop();
}
/*-------------------------------------
SubSystem Tick Time
-------------------------------------*/
void GameSystem::update_tick_time()
{
// Frame Time Management
const uint64_t currTime = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch()
).count();
tickTime = currTime - prevTime;
prevTime = currTime;
}
/*-------------------------------------
Update all internal game states.
-------------------------------------*/
void GameSystem::update_game_states()
{
if (!gameList.size())
{
LS_LOG_ERR("No game states are available!");
}
for (std::size_t i = 0; i < gameList.size(); ++i)
{
GameState* const pState = gameList[i];
switch (pState->get_state())
{
case game_state_status_t::RUNNING:
pState->on_run();
break;
case game_state_status_t::PAUSED:
pState->on_pause();
break;
case game_state_status_t::STOPPING:
pState->on_stop();
pState->set_state(game_state_status_t::STOPPED);
break;
case game_state_status_t::STOPPED:
pop_game_state(i);
i -= 1; // the size of "this->gameList" has shrunk by one
break;
case game_state_status_t::STARTING:
// if a state starts successfully, run it on the next iteration
if (pState->on_start() == true)
{
pState->set_state(game_state_status_t::RUNNING);
}
else
{
// stop a state and delete it on the next iteration.
LS_LOG_ERR("ERROR: A new gameState was unable to start.");
pState->set_state(game_state_status_t::STOPPED);
}
break;
default:
break;
}
}
}
/*-------------------------------------
SubSystem State Addition
-------------------------------------*/
bool GameSystem::push_game_state(GameState* const pState)
{
if (pState == nullptr)
{
LS_LOG_ERR("ERROR: A null pointer was pushed onto the game stack.\n");
return false;
}
// states will be started in the "updateGameStates()" method.
pState->set_parent_system(*this);
pState->set_state(game_state_status_t::STARTING);
gameList.push_back(pState);
return true;
}
/*-------------------------------------
SubSystem State Addition
-------------------------------------*/
void GameSystem::pop_game_state()
{
LS_DEBUG_ASSERT(gameList.size());
pop_game_state(gameList.size() - 1);
}
/*-------------------------------------
SubSystem State Removal
-------------------------------------*/
void GameSystem::pop_game_state(GameState* const pState)
{
for (std::size_t i = 0; i < gameList.size(); ++i)
{
if (gameList[i] == pState)
{
pop_game_state(i);
break;
}
}
}
/*-------------------------------------
SubSystem State Removal
-------------------------------------*/
void GameSystem::pop_game_state(std::size_t index)
{
LS_DEBUG_ASSERT(index < gameList.size());
GameState* const pState = gameList[index];
// Allow "pState->on_stop()" to execute in the main loop
if (!pState->is_stopped())
{
pState->set_state(game_state_status_t::STOPPING);
return;
}
delete pState; // no guarantee that on_stop() is in a state's destructor.
gameList.erase(gameList.begin() + index);
}
/*-------------------------------------
Clear SubSystem States
-------------------------------------*/
void GameSystem::clear_game_states()
{
for (GameState* const pState : gameList)
{
pState->set_state(game_state_status_t::STOPPING);
// Don't delete game states here. Wait for them to do their cleanup
// routines in the main loop.
}
}
/*-------------------------------------
SubSystem State Retrieval
-------------------------------------*/
GameState const* GameSystem::get_game_state(std::size_t index) const
{
LS_DEBUG_ASSERT(index < gameList.size());
return gameList[index];
}
/*-------------------------------------
SubSystem State Retrieval
-------------------------------------*/
GameState* GameSystem::get_game_state(std::size_t index)
{
LS_DEBUG_ASSERT(index < gameList.size());
return gameList[index];
}
/*-------------------------------------
SubSystem State Indexing
-------------------------------------*/
std::size_t GameSystem::get_game_state_index(GameState* const pState) const
{
for (std::size_t i = 0; i < gameList.size(); ++i)
{
if (gameList[i] == pState)
{
return i;
}
}
return UINT_MAX;
}
} // end game namespace
} // end ls namespace
| true |
539b6710709059ae771a8a196dc4cd6a55512c53 | C++ | gloshkaj/Assembler | /Instruction.cpp | UTF-8 | 5,998 | 3.21875 | 3 | [] | no_license | #include "stdafx.h"
#include "Instruction.h"
#include <sstream>
#include <iterator>
/*
NAME
ParseInstruction - Parses the current line in the file and gets the instruction type.
SYNOPSIS
Instruction::InstructionType ParseInstruction(string &a_buff);
DESCRIPTION
This function will determine the type of instruction in "a_buff".
RETURNS
The type of instruction
*/
Instruction::InstructionType Instruction::ParseInstruction(string & a_buff) {
// Machine Language
string inst_ops[] { "ADD", "add", "SUB", "sub", "MULT", "mult", "DIV", "div", "LOAD", "load", "STORE", "store", "READ", "read", "WRITE", "write", "B", "b", "BM", "bm", "BZ", "bz", "BP", "bp", "HALT", "halt"};
// Assembler Instruction
string assem_ops[] { "DC", "dc", "DS", "ds", "ORG", "org" };
// End
string end_ops[] { "END", "end", "eND", "End", "EnD", "ENd", "eNd", "enD"};
// Halt
string halt_ops[]{ "HALT, halt", "Halt", "HALt", "HAlT", "HaLt", "hALT", "hALt", "HAlt", "HalT", "HaLT", "hAlT", "halT", "haLt", "haLT", "hAlt"};
m_instruction = a_buff; // Save original instruction for printing
if (m_instruction.at(0) == ';' || m_instruction.empty()) { // If we have a ; at the beginning of the line or the line is blank then this must be a comment
return ST_Comment;
}
int j = 0;
while (m_instruction[j] == ' ' && j != m_instruction.length()) { // Remove all trailing spaces
j++;
}
if (find(begin(end_ops), end(end_ops), m_instruction.substr(j, 3)) != end(end_ops)) { // End instruction
return ST_End;
}
if (find(begin(halt_ops), end(halt_ops), m_instruction.substr(j, 4)) != end(halt_ops)) { // Halt instruction
return ST_MachineLanguage;
}
int is = a_buff.find(";"); // Remove all characters past and including ;
if (is != string::npos) {
a_buff.erase(is);
}
for (int i = 0; i < a_buff.length(); i++) { // Convert to lowercase because instructions are not case sensitive
if (!isspace(a_buff.at(i)) && !ispunct(a_buff.at(i))) {
a_buff.at(i) = tolower(a_buff.at(i));
}
}
// Use istringstream to parse instruction into label, opcode, and operand
istringstream input(a_buff);
string tmp1, tmp2, tmp3, tmp4;
input >> tmp1 >> tmp2 >> tmp3 >> tmp4;
if (a_buff[0] == ' ') { // If the beginning has a space then there is no label
m_Label = "";
m_OpCode = tmp1;
m_Operand = tmp2;
// If the end is not empty or some parts on the beginning are empty then this is an illegal instruction. Report error during pass II
if (!tmp3.empty()) {
return ST_IllegalInstruction;
}
}
else { // Otherwise we have a label
m_Label = tmp1;
m_OpCode = tmp2;
m_Operand = tmp3;
// Same as before, must check for missing or extra parts of instruction
if (!tmp4.empty()) {
return ST_IllegalInstruction;
}
}
if (find(begin(assem_ops), end(assem_ops), m_OpCode) != end(assem_ops)) { // Assembler instruction
m_type = ST_AssemblerInstr;
}
else if (find(begin(inst_ops), end(inst_ops), m_OpCode) != end(inst_ops)){ // Machine Language Instruction
m_type = ST_MachineLanguage;
}
else { // If it is not any type then it must be illegal
m_type = ST_IllegalInstruction;
}
return m_type; // Return the type of instruction
}
/*
NAME
LocationNextInstruction - computes the location of the next instruction given the current one.
SYNOPSIS
int LocationNextInstruction(int a_loc);
DESCRIPTION
This function will compute the location of the next instruction given the current.
RETURNS
loc + 1 unless the operand is a DS or an ORG in which case the location is added on to the previous one
*/
int Instruction::LocationNextInstruction(int a_loc) {
// If this is a DS or an ORG add the operand onto the location. Must convert string to integer
if (m_OpCode == "DS" || m_OpCode == "ds") { // Each time, return the base case, loc + 1 if the operand is not numeric
for (int i = 0; i < m_Operand.length(); i++) {
if (!isdigit(m_Operand.at(i))) return a_loc + 1;
}
return a_loc + stoi(m_Operand);
}
if (m_OpCode == "ORG" || m_OpCode == "org") {
for (int i = 0; i < m_Operand.length(); i++) {
if (!isdigit(m_Operand.at(i))) return a_loc + 1;
}
return a_loc + stoi(m_Operand);
}
if (m_OpCode == "DC" || m_OpCode == "dc") {
for (int i = 0; i < m_Operand.length(); i++) {
if (!isdigit(m_Operand.at(i))) return a_loc;
}
}
// Otherwise add 1 to the location
return a_loc + 1;
}
/*
NAME
computeNumOpCode - determines the number associated with a particular instruction.
SYNOPSIS
void PassII();
DESCRIPTION
This function will compute the number between 0 and 13 associated with the instruction.
RETURNS
A number between 0 and 13 based on the opcode
*/
int Instruction::computeNumOpCode() {
if (m_OpCode == "ADD" || m_OpCode == "add") {
m_NumOpCode = 1; // ADD
}
else if (m_OpCode == "SUB" || m_OpCode == "sub") {
m_NumOpCode = 2; // SUBTRACT
}
else if (m_OpCode == "MULT" || m_OpCode == "mult") {
m_NumOpCode = 3; // MULT
}
else if (m_OpCode == "DIV" || m_OpCode == "div") {
m_NumOpCode = 4; // DIV
}
else if (m_OpCode == "LOAD" || m_OpCode == "load") {
m_NumOpCode = 5; // LOAD
}
else if (m_OpCode == "STORE" || m_OpCode == "store") {
m_NumOpCode = 6; // STORE
}
else if (m_OpCode == "READ" || m_OpCode == "read") {
m_NumOpCode = 7; // READ
}
else if (m_OpCode == "WRITE" || m_OpCode == "write") {
m_NumOpCode = 8; // WRITE
}
else if (m_OpCode == "B" || m_OpCode == "b") {
m_NumOpCode = 9; // B
}
else if (m_OpCode == "BM" || m_OpCode == "bm") {
m_NumOpCode = 10; // BM
}
else if (m_OpCode == "BZ" || m_OpCode == "bz") {
m_NumOpCode = 11; // BZ
}
else if (m_OpCode == "BP" || m_OpCode == "bp") {
m_NumOpCode = 12; // BP
}
else if (m_OpCode == "HALT" || m_OpCode == "halt") {
m_NumOpCode = 13; // HALT
}
else {
m_NumOpCode = 0; // This means it has to be an assembler instruction
}
return m_NumOpCode;
} | true |
52367ba1b03083c5a8a662f1a01516a66181ec8e | C++ | explorer85/projects | /enginetest/multiinterface.h | UTF-8 | 1,295 | 2.796875 | 3 | [] | no_license | #ifndef INTERFACE_H
#define INTERFACE_H
#include <QDebug>
namespace multiinterface {
class Base /*:*/ /*public QObject*/ {
public:
virtual ~Base() = default;
void test() {}
};
class IRenderable : virtual public Base {
public:
virtual void render() = 0;
};
class Inputable : virtual public Base {
public:
virtual void input(int mouse) = 0;
};
class MapObject : public QObject, public IRenderable, public Inputable {
Q_OBJECT
public:
void render() { qDebug() << "MapObject::render"; }
void input(int /*mouse*/) { qDebug() << "MapObject::input"; }
public slots:
void onReceive() {}
};
class Gridbject : public QObject, public IRenderable {
Q_OBJECT
public:
void render() { qDebug() << "Gridbject::render"; }
};
class Engine {
public:
void addObject(Base* obj) {
objects.push_back(obj);
//obj->input(5);
if (IRenderable* ir = dynamic_cast<IRenderable*>(obj)) {
irobjects.push_back(ir);
}
if (Inputable* ii = dynamic_cast<Inputable*>(obj)) {
iiobjects.push_back(ii);
}
}
void update() {
for (IRenderable* ptr : irobjects) {
ptr->render();
}
for (Inputable* ptr : iiobjects) {
ptr->input(5);
}
}
std::vector<IRenderable*> irobjects;
std::vector<Inputable*> iiobjects;
std::vector<Base*> objects;
};
}
#endif // INTERFACE_H
| true |
722490ba4e9f575de49032ee2c97af212dad9692 | C++ | zrpllvv/ADS-Codeforces | /cd_271_A.cpp | UTF-8 | 569 | 2.9375 | 3 | [
"MIT"
] | permissive | //@author: zrpllvv
//link: https://codeforces.com/contest/271/problem/A
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <set>
using namespace std;
bool func(int god){
set<char> unique;
string s = to_string(god);
int size = s.size();
for(int i = 0; i < size; i++){
unique.insert(s[i]);
}
return(unique.size() == s.size());
}
int main(){
int year;
cin >> year;
int i = 1;
while(true){
if(func(i+year)){
cout << i + year;
break;
}
i++;
}
return 0;
}
| true |
07cf76fe3923f26ad5352d48b86057067e3c5e5a | C++ | TheAnswer/Tools | /SWGHeightDump/engine/thread/Mutex.h | UTF-8 | 1,375 | 3.078125 | 3 | [
"WTFPL"
] | permissive | #ifndef MUTEX_H_
#define MUTEX_H_
// made by Oru
#include "../system.h"
class Mutex {
pthread_mutex_t mutex;
bool doLog;
string lockName;
int lockCount;
int currentCount;
public:
Mutex() {
//mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_init(&mutex, NULL);
doLog = true;
lockName = "Mutex";
lockCount = 0;
}
Mutex(const string& s) {
//mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_init(&mutex, NULL);
doLog = true;
lockName = s;
lockCount = 0;
}
void setMutexLogging(bool dolog) {
doLog = dolog;
}
void setLockName(const string& s) {
lockName = s;
}
inline void lock(bool doLock = true) {
if (!doLock)
return;
int res = pthread_mutex_lock(&mutex);
if (res != 0)
cout << "(" << /*Time::currentNanoTime()*/0 << " nsec) lock() failed on Mutex \'" << lockName << "\' (" << res << ")\n";
}
inline bool tryLock() {
return pthread_mutex_trylock(&mutex) == 0;
}
inline void unlock(bool doLock = true) {
if (!doLock)
return;
int res = pthread_mutex_unlock(&mutex);
if (res != 0) {
cout << "(" << /*Time::currentNanoTime()*/0 << " nsec) unlock() failed on Mutex \'" << lockName << "\' (" << res << ")\n";
}
}
};
#endif /*MUTEX_H_*/
| true |
b1f884546407eec63aa911d4a92510f432a7096c | C++ | nomigori96/Compi3 | /ParserFunctions_old.cpp | UTF-8 | 8,792 | 2.640625 | 3 | [] | no_license |
#include "ParserFunctions.hpp"
#include "symbol_table.hpp"
#include "hw3_output.hpp"
using namespace output;
SymbolTable symbol_table;
bool is_in_loop = false;
string curr_function_return_type = "";
extern int yylineno;
void CheckMainExists()
{
if (symbol_table.DoesSymbolExists("main") == SYMBOL){
FunctionSymbolTableRecord* main_record =
dynamic_cast<FunctionSymbolTableRecord*>(symbol_table.GetSymbolRecordById("main"));
vector<tuple<string,string, bool>> main_record_args = main_record->GetFuncArgs();
string ret = main_record->GetFuncReturnType();
if (!(main_record_args.empty() && ret == "void")){
errorMainMissing();
exit(0);
}
}
else {
errorMainMissing();
exit(0);
}
}
void AddFunctionSymbolIfNotExists(
const string& symbol_name,
const vector<tuple<string,string,bool>>& args,
const string& ret_type)
{
if (symbol_table.DoesSymbolExists(symbol_name) != DOESNT_EXIST){
errorDef(yylineno, symbol_name);
exit(0);
}
//TODO - before insertion need to check that all args are of legal types (only check if its a legal enum)
else {
symbol_table.InsertFunction(symbol_name, args, ret_type);
}
}
void AddEnumSymbolIfNotExists(
const string& symbol_name,
const vector<string>& enum_values)
{
if (symbol_table.DoesSymbolExists(symbol_name) != DOESNT_EXIST){
errorDef(yylineno, symbol_name);
exit(0);
}
else {
symbol_table.InsertEnum(symbol_name, enum_values);
}
}
void OpenNewScope()
{
symbol_table.OpenScope();
}
void CloseCurrentScope()
{//TODO - need to change how we print the types
endScope();
vector<SymbolTableRecord*> currentScope = symbol_table.GetCurrentScope();
for (auto &symbol : currentScope){
if (symbol->IsEnumType()){
string enum_str("enum ");//TODO - need to change offset to 0?
printID(symbol->GetName(), symbol->GetOffset(), enum_str + symbol->GetType());
} else if (symbol->GetType() == "function"){
string retType = dynamic_cast<FunctionSymbolTableRecord*>(symbol)->GetFuncReturnType();
vector<string> argTypes = MapArgsToTypes(dynamic_cast<FunctionSymbolTableRecord*>(symbol)->GetFuncArgs());
string type = makeFunctionType(retType, argTypes);
printID(symbol->GetName(), 0, type);
} else if (symbol->GetType() == "enum"){
//Do nothing
}
else {//TODO - need to change the types printing
printID(symbol->GetName(), symbol->GetOffset(), symbol->GetType());
}
}
for (auto &symbol : currentScope){
if (symbol->GetType() == "enum"){
vector<string> enumValues = dynamic_cast<EnumSymbolTableRecord*>(symbol)->GetEnumValues();
printEnumType(symbol->GetName(), enumValues);
}
}
symbol_table.CloseCurrentScope();
}
void AddFuncArgsToSymbolTable(vector<tuple<string,string,bool>>& args)
{
int counter = -1;
for (auto &arg : args) {
if (symbol_table.DoesSymbolExists(get<1>(arg)) != DOESNT_EXIST)
{
errorDef(yylineno, get<1>(arg));
exit(0);
}
else {
symbol_table.InsertFunctionArgSymbol(
get<1>(arg),
get<0>(arg),
counter,
get<2>(arg));
}
counter--;
}
}
void CheckTypesMatch(vector<string>& expected, string& given){
for (string &expected_option : expected){
if (given == expected_option){
return;
}
}
errorMismatch(yylineno);
exit(0);
}
string DetermineBinopReturnType(string& first, string& second){
if(first == "byte" && second == "byte"){
return "byte";
}
return "int";
}
//TODO - maybe should use errorUndefEnumValue
string GetExpressionTypeById(string& id){
if (symbol_table.DoesSymbolExists(id) == SYMBOL){
SymbolTableRecord* wantedRecord = symbol_table.GetSymbolRecordById(id);
string recordType = wantedRecord->GetType();
if (recordType == "function" || recordType == "enum"){
errorUndef(yylineno, id);
exit(0);
}
return recordType;
}
if (symbol_table.DoesSymbolExists(id) == ENUM_VALUE){
return symbol_table.FindEnumTypeByGivenValue(id);
}
errorUndef(yylineno, id);
exit(0);
}
bool AreArgsEqual(vector<string> expListTypes, vector<tuple<string, string, bool>> fromRecord){
if (expListTypes.size() != fromRecord.size()){
return false;
}
vector<string>::iterator expListTypeIterator = expListTypes.begin();
vector<tuple<string, string, bool>>::iterator fromRecordIterator = fromRecord.begin();
while (expListTypeIterator != expListTypes.end()){
if(*expListTypeIterator != get<0>(*fromRecordIterator)){
return false;
}
}
return true;
}
vector<string> MapArgsToTypes(vector<tuple<string, string, bool>> fromRecord){
vector<string> onlyTypes;
for(auto &currArg : fromRecord){
string argType;
tie(argType, ignore, ignore) = currArg;
onlyTypes.push_back(argType);
}
return onlyTypes;
}
string CheckFunction(string& id, vector<string> expListTypes){
if (symbol_table.DoesSymbolExists(id) == SYMBOL){
SymbolTableRecord* wantedRecord = symbol_table.GetSymbolRecordById(id);
if (wantedRecord->GetType() != "function"){
errorUndefFunc(yylineno, id);
exit(0);
}
vector<tuple<string, string, bool>> fromRecord = dynamic_cast<FunctionSymbolTableRecord*>(wantedRecord)->GetFuncArgs();
if (!AreArgsEqual(expListTypes, fromRecord)){
vector<string> expectedTypes = MapArgsToTypes(fromRecord);
errorPrototypeMismatch(yylineno, id, expectedTypes);
exit(0);
}
return dynamic_cast<FunctionSymbolTableRecord*>(wantedRecord)->GetFuncReturnType();
}
errorUndefFunc(yylineno, id);
exit(0);
}
bool IsVarTypeValid(string& type){
if(type == "byte" || type == "int" || type == "bool"){
return true;
}
return symbol_table.DoesSymbolExists(type) == SYMBOL &&
symbol_table.GetSymbolRecordById(type)->GetType() == "enum";
}
void AddVariableSymbolIfNotExists(string& symbol_name,
string& type,
bool is_enum_type){
if (symbol_table.DoesSymbolExists(symbol_name) != DOESNT_EXIST){
errorDef(yylineno, symbol_name);
exit(0);
}
if (IsVarTypeValid(type)){
symbol_table.InsertSymbol(symbol_name, type, is_enum_type);
}
else {
errorUndefEnum(yylineno, symbol_name);
exit(0);
}
}
bool IsImplicitCastAllowed(string& lType, string& expType){
return (lType == "int" && expType == "byte") || lType == expType;
}
void HandleAssignment(string& lType, string& expType, string& id){
if (lType != expType && !IsImplicitCastAllowed(lType, expType)){
errorMismatch(yylineno);
exit(0);
}
AddVariableSymbolIfNotExists(id, lType, false);
}
void HandleAssignmentForExistingVar(string& id, string& expType){
if (symbol_table.DoesSymbolExists(id) != SYMBOL){
errorUndef(yylineno, id);
exit(0);
}
string wanted_type = symbol_table.GetSymbolRecordById(id)->GetType();
if (wanted_type != expType && !IsImplicitCastAllowed(wanted_type, expType)){
if(wanted_type == "byte" || wanted_type == "int" || wanted_type == "bool" ||
symbol_table.GetSymbolRecordById(id)->IsEnumType()){
errorMismatch(yylineno);
}
else {
errorUndef(yylineno, id);
}
exit(0);
}
}
void FlipLoopStatus(){
is_in_loop = !is_in_loop;
}
void CheckIfBreakInLoop(){
if (!is_in_loop){
errorUnexpectedBreak(yylineno);
exit(0);
}
}
void CheckIfContinueInLoop(){
if (!is_in_loop){
errorUnexpectedContinue(yylineno);
exit(0);
}
}
void UpdateCurrFunctionRetType(string& retType){
curr_function_return_type = retType;
}
void CheckReturnValid(string& givenType){
if (curr_function_return_type != givenType && !IsImplicitCastAllowed(curr_function_return_type, givenType)){
errorMismatch(yylineno);
exit(0);
}
}
void ExplicitCast(string& castToType, string& castFromType){
if (!(castToType == "int" && castFromType == "enum")){
errorMismatch(yylineno);
exit(0);
}
}
void CheckNumValidity(int byteNum){
if (byteNum > 255){
errorByteTooLarge(yylineno, to_string(byteNum));
exit(0);
}
}
| true |
0bdbc0d8b064be37d601133d75dcc09e1a1da327 | C++ | SabineHU/Raytracer | /src/light/point_light.hh | UTF-8 | 433 | 2.75 | 3 | [] | no_license | #pragma once
#include "light.hh"
#include "vector3.hh"
class PointLight : public Light {
public:
PointLight();
PointLight(const Vect&, const Color&);
PointLight(const Vect&, const Color&, double);
virtual Vect get_light_position() const override;
virtual Color get_light_color() const override;
virtual double get_intensity() const override;
Vect position;
Color color;
double intensity;
};
| true |
c8752871b53de6d5f505e5c8969130c755f25337 | C++ | Razvan2109/OOP_Project_Laundry | /main.cpp | UTF-8 | 21,861 | 2.703125 | 3 | [] | no_license | #include <iostream>
#include <stdlib.h>
#include <cstring>
#include <typeinfo>
#include <windows.h>
#include <fstream>
using namespace std;
ifstream f;
class haine;
class masina;
class proces
{
char tip[30];
float detergent;
float durata;
public:
friend void calcare(haine&);
friend float timpTotal(haine&);
friend int plasare(haine*,masina&);
friend void proceseParcurse(haine&);
proces()
{
strcpy(tip,"0");
}
};
class haine
{
protected:
char *culoare;
proces procese[4];
float greutate;
float detergentNecesar;
float timpCalcare;
bool inMasina;
int client; ///Cu aceasta variabila tinem minte clientul caruia ii apartine haina, pentru a o plasa corespunzator in matricea finala
public:
void setClient(int cl)
{
this->client=cl;
}
int getClient()
{
return this->client;
}
int getDetergent()
{
return this->detergentNecesar;
}
friend int eGol(haine**,int,int );
friend void calcare(haine&);
friend float timpTotal(haine&);
friend void afisare(haine&);
friend void proceseParcurse(haine&);
friend int plasare(haine* ha,masina& ma);
friend istream& operator>>(istream&, haine&);
friend ostream& operator<<(ostream&, haine&);
haine& operator=(const haine& ob)
{
this->client=ob.client;
this->culoare=ob.culoare;
this->detergentNecesar=ob.detergentNecesar;
this->greutate=ob.greutate;
for(int i=0;i<4;i++)
{this->procese[i]=ob.procese[i];}
this->timpCalcare=ob.timpCalcare;
}
virtual void f() {}
};
void afisare(haine &ob)
{
cout<<endl;
cout<<"Culoare: "<<ob.culoare<<endl;
cout<<"Greutate(kg): "<<ob.greutate<<endl<<"Detergent necesar pentru spalare(grame): "<<ob.detergentNecesar<<endl<<"Timp necesar pentru calcare(minute): "<<ob.timpCalcare<<endl;
}
float timpTotal(haine& ob)
{
float timp=0;
for(int i=0; i<4; i++)
{
if(strcmp(ob.procese[i].tip,"0")!=0)
{
timp=timp+ob.procese[i].durata;
}
}
return timp;
}
void proceseParcurse(haine &ob)
{
cout<<endl<<typeid(ob).name();
for(int i=0; i<4; i++)
{
if(strcmp(ob.procese[i].tip,"0")!=0)
{
cout<<endl<<endl;
cout<<ob.procese[i].tip<<endl<<"Detergent utilizat: "<<ob.procese[i].detergent<<endl<<"Timpul executarii: "<<ob.procese[i].durata<<endl;
}
}
}
istream& operator>>(istream& in, haine& ob)
{
in>>ob.culoare;
return in;
}
ostream& operator<<(ostream& out, haine& ob)
{
out<<"Culoare: "<<ob.culoare<<endl<<"Greutate(kg): "<<ob.greutate<<endl<<"Detergent necesar pentru spalare(grame): "<<ob.detergentNecesar<<endl<<"Timp necesar pentru calcare(minute): "<<ob.timpCalcare<<endl;
return out;
}
class camasa:public haine
{
public:
camasa(char* culoare);
};
camasa::camasa(char*culoare="Nedefinit")
{
this->culoare=new char;
strcpy(this->culoare,culoare);
this->greutate=0.2;
this->detergentNecesar=50;
this->timpCalcare=(120*greutate)/60;
this->inMasina=false;
}
class rochie:public haine
{
public:
rochie(char* culoare);
};
rochie::rochie(char*culoare="Nedefinit")
{
this->culoare=new char;
strcpy(this->culoare,culoare);
this->greutate=0.45;
this->detergentNecesar=50;
this->timpCalcare=(140*greutate)/60;
this->inMasina=false;
}
class pantaloni:public haine
{
public:
pantaloni(char* culoare);
};
pantaloni::pantaloni(char*culoare="Nedefinit")
{
this->culoare=new char;
strcpy(this->culoare,culoare);
this->greutate=0.35;
if(strcmp(this->culoare,"deschisa")==0)
this->detergentNecesar=50;
else
this->detergentNecesar=100;
this->timpCalcare=(90*greutate)/60;
this->inMasina=false;
}
class palton:public haine
{
public:
palton(char* culoare);
friend istream& operator>>(istream&, palton&);
friend ostream& operator<<(ostream&, palton&);
};
istream& operator>>(istream& in, palton& ob)
{
in>>ob.culoare;
return in;
}
ostream& operator<<(ostream& out, palton& ob)
{
out<<"Culoare: "<<ob.culoare<<endl<<"Greutate(kg): "<<ob.greutate<<endl<<"Detergent necesar pentru spalare(grame): "<<ob.detergentNecesar<<endl<<"Timp necesar pentru calcare(minute): "<<ob.timpCalcare<<endl;
out<<"Haina este grea";
return out;
}
palton::palton(char*culoare="Nedefinit")
{
this->culoare=new char;
strcpy(this->culoare,culoare);
this->greutate=1.2;
this->detergentNecesar=100*greutate;
this->timpCalcare=0;
this->inMasina=false;
}
class geaca:public haine
{
public:
geaca(char* culoare);
};
geaca::geaca(char*culoare="Nedefinit")
{
this->culoare=new char;
strcpy(this->culoare,culoare);
this->greutate=0.8;
this->detergentNecesar=100*greutate;
this->timpCalcare=0;
this->inMasina=false;
}
class costum:public haine
{
public:
costum(char* culoare);
};
costum::costum(char*culoare="Nedefinit")
{
this->culoare=new char;
strcpy(this->culoare,culoare);
this->greutate=0.95;
this->detergentNecesar=100*greutate;
this->timpCalcare=(150*0.6+90*0.35)/60;
this->inMasina=false;
}
class masina
{
protected:
float capacitate;
float spatiuOcupat;
float timpFunctionare;
haine **haineIn;
int nrHaine;
bool ocupat;
public:
float getSpatiuOcupat()
{
return spatiuOcupat;
}
float getCapacitate()
{
return capacitate;
}
int getNrHaine()
{
return nrHaine;
}
friend haine* scoatere(masina &ma);
friend void arataContinut(masina&);
friend void pornire(masina&,masina&);
friend void afisare(masina&);
friend int plasare(haine* ha,masina& ma);
virtual ~masina() {};
friend istream& operator>>(istream&, masina&);
friend ostream& operator<<(ostream&, masina&);
masina& operator=(const masina& ob)
{
this->capacitate=ob.capacitate;
this->spatiuOcupat=ob.spatiuOcupat;
this->timpFunctionare=ob.timpFunctionare;
this->nrHaine=ob.nrHaine;
for(int i=0;i<nrHaine;i++)
{
this->haineIn[i]=ob.haineIn[i];
}
}
};
void arataContinut(masina& ob)
{
// system("cls");
if (ob.nrHaine==0)
cout<<"Masina este goala!";
else
{
cout<<"Spatiu ocupat: "<<ob.spatiuOcupat<<" din "<<ob.capacitate<<endl;
for(int i=0; i<ob.nrHaine; i++)
{
cout<<endl;
cout<<typeid(*ob.haineIn[i]).name();
}
}
}
int eGol(haine **a,int m,int n)
{
for(int i=0; i<m; i++)
{
for(int j=0; i<n; j++)
{
if(strcmp(a[i][j].culoare,"nedefinit")!=0)
return 0;
}
}
return 1;
}
void afisare(masina& ob)
{
cout<<endl;
cout<<"Capacitate(Kg): "<<ob.capacitate<<endl<<"Timp functionare(min): "<<ob.timpFunctionare<<endl;
}
istream& operator>>(istream& in, masina& ob)
{
return in;
}
ostream& operator<<(ostream& out, masina& ob)
{
out<<(haine&)ob;
out<<"Haina este de categorie grea";
return out;
}
class spalat:public masina
{
public:
spalat();
};
spalat::spalat()
{
haineIn=new haine*[100];
capacitate=6;
spatiuOcupat=0;
nrHaine=0;
timpFunctionare=200;
ocupat=false;
}
class spalatGreu:public masina
{
public:
spalatGreu();
};
spalatGreu::spalatGreu()
{
haineIn=new haine*[100];
capacitate=10;
spatiuOcupat=0;
nrHaine=0;
timpFunctionare=230;
ocupat=false;
}
class stors:public masina
{
public:
stors();
};
stors::stors()
{
haineIn=new haine*[100];
capacitate=6;
spatiuOcupat=0;
nrHaine=0;
timpFunctionare=30;
ocupat=false;
}
class uscat:public masina
{
int incapere;
public:
uscat();
friend void afisare(uscat&);
};
void afisare(uscat& ob)
{
cout<<endl;
cout<<"Capacitate(obiecte): "<<ob.incapere<<endl<<"Timp functionare(min): "<<ob.timpFunctionare<<endl;
}
uscat::uscat()
{
haineIn=new haine*[100];
capacitate=20;
spatiuOcupat=0;
nrHaine=0;
timpFunctionare=60;
ocupat=false;
}
int plasare(haine* ha,masina& ma) ///Functie care plaseaza un obiect de tip haine* intr-o masina corespunzatoare in functiile de procesele prin care aceasta a trecut deja.
{
if(strcmp(ha->procese[0].tip,"0")==0)
{
///cout<<"intra";
if(typeid(*ha)==typeid(camasa)||typeid(*ha)==typeid(rochie)||typeid(*ha)==typeid(pantaloni))
{
///cout<<"intra";
if(typeid(ma)==typeid(spalat) && ma.capacitate>ha->greutate)
///cout<<"intra";
if(strcmp(ha->culoare,ma.haineIn[0]->culoare)==0 || ma.nrHaine==0)
{
///cout<<"intra";
strcpy(ha->procese[0].tip,"spalare");
ha->procese[0].detergent=ha->detergentNecesar;
ha->procese[0].durata=ma.timpFunctionare;
ma.haineIn[ma.nrHaine]=ha;
ma.spatiuOcupat=ma.spatiuOcupat+ha->greutate;
ma.nrHaine++;
return 1;
}
}
if(typeid(*ha)==typeid(palton)||typeid(*ha)==typeid(geaca)||typeid(*ha)==typeid(costum))
{
if(typeid(ma)==typeid(spalatGreu) && ma.capacitate>ha->greutate)
if(strcmp(ha->culoare,ma.haineIn[0]->culoare)==0 || ma.nrHaine==0)
{
strcpy(ha->procese[0].tip,"spalare");
ha->procese[0].detergent=ha->detergentNecesar;
ha->procese[0].durata=ma.timpFunctionare;
ma.haineIn[ma.nrHaine]=ha;
ma.spatiuOcupat=ma.spatiuOcupat+ha->greutate;
ma.nrHaine++;
return 1;
}
}
if(typeid(*ha)==typeid(costum))
{
if(typeid(ma)==typeid(spalat) && ma.capacitate>ha->greutate)
if(typeid(ma.haineIn[ma.nrHaine])==typeid(costum) || ma.nrHaine==0)
{
strcpy(ha->procese[0].tip,"spalare");
ha->procese[0].detergent=ha->detergentNecesar;
ha->procese[0].durata=ma.timpFunctionare;
ma.haineIn[ma.nrHaine]=ha;
ma.spatiuOcupat=ma.spatiuOcupat+ha->greutate;
ma.nrHaine++;
return 1;
}
}
}
if(strcmp(ha->procese[0].tip,"0")!=0 && strcmp(ha->procese[1].tip,"0")==0)
{
if(typeid(*ha)==typeid(camasa)||typeid(*ha)==typeid(rochie)||typeid(*ha)==typeid(pantaloni)||typeid(*ha)==typeid(costum))
if(typeid(ma)==typeid(stors) && ma.capacitate>ha->greutate)
{
strcpy(ha->procese[1].tip,"stoarcere");
ha->procese[1].detergent=0;
ha->procese[1].durata=ma.timpFunctionare;
ma.haineIn[ma.nrHaine]=ha;
ma.spatiuOcupat=ma.spatiuOcupat+ha->greutate;
ma.nrHaine++;
return 1;
}
if(typeid(*ha)==typeid(palton)||typeid(*ha)==typeid(geaca))
if(typeid(ma)==typeid(uscat) && ma.capacitate>ma.nrHaine)
{
strcpy(ha->procese[1].tip,"uscare");
ha->procese[1].durata=ma.timpFunctionare;
ha->procese[1].detergent=0;
ma.haineIn[ma.nrHaine]=ha;
ma.nrHaine++;
return 1;
}
}
if(strcmp(ha->procese[1].tip,"0")!=0 && strcmp(ha->procese[2].tip,"0")==0)
{
if(typeid(*ha)==typeid(camasa)||typeid(*ha)==typeid(rochie)||typeid(*ha)==typeid(pantaloni)||typeid(*ha)==typeid(costum))
if(typeid(ma)==typeid(uscat) && ma.capacitate>ma.nrHaine)
{
strcpy(ha->procese[2].tip,"uscare");
ha->procese[2].detergent=0;
ha->procese[2].durata=ma.timpFunctionare;
ma.haineIn[ma.nrHaine]=ha;
ma.nrHaine++;
return 1;
}
}
return 0;
}
void calcare(haine& ha)
{
if(strcmp(ha.procese[3].tip,"0")==0)
{
strcpy(ha.procese[3].tip,"calcare");
ha.procese[3].detergent=0;
ha.procese[3].durata=ha.timpCalcare;
}
}
void pornire(masina& ma,masina& ma2)
{
int i;
for(i=0; i<ma.nrHaine; i++)
{
haine* aux=ma.haineIn[i];
/// cout<<"\n"<<typeid(*aux).name()<<"\n"; ->afiseaza elementele masinii din care se muta (folosit pentru testare)
if(plasare(aux,ma2))
{
cout<<"\n plasam in masina "<<typeid(ma2).name(); ///Functie care "porneste" masina, scotand toate hainele din ea si predandu-le urmatoarei masini
cout<<"\n"<<typeid(*aux).name()<<"\n";
proceseParcurse(*aux);
}
}
ma.spatiuOcupat=0;
ma.nrHaine=0;
}
haine* scoatere(masina &ma) ///Functie care scoate ultimul obiect din masina. Folosita pentru a scoate obiectele din masinile de uscat fara a le muta in alta masina.
{
haine* a;
if(ma.nrHaine==0)
{
a=new camasa("nedefinit");
return a;
}
if(typeid(*(ma.haineIn[ma.nrHaine]))==typeid(palton)||typeid(*(ma.haineIn[ma.nrHaine]))==typeid(geaca))
{
a=new haine;
a=ma.haineIn[ma.nrHaine];
ma.nrHaine--;
return a;
}
if(typeid(*(ma.haineIn[ma.nrHaine]))==typeid(camasa)||typeid(*(ma.haineIn[ma.nrHaine]))==typeid(rochie)||typeid(*(ma.haineIn[ma.nrHaine]))==typeid(pantaloni)||typeid(*(ma.haineIn[ma.nrHaine]))==typeid(costum))
{
a=new haine;
calcare(*(ma.haineIn[ma.nrHaine]));
a=ma.haineIn[ma.nrHaine];
ma.nrHaine--;
return a;
}
}
bool doarCifre(char* s)
{
int i;
for(i=0;i<strlen(s);i++)
{
if (strchr("0123456789",s[i])==0) return false;
}
return true;
}
int main()
{
cout << "Hello world!" << endl;
/*camasa test("inchisa");
afisare(test);
rochie test2("deschisa");
afisare(test2);
pantaloni test3("deschisa");
afisare(test3);
palton test4("inchisa");
afisare (test4);
palton test5("deschisa");
afisare (test5);
costum test6("inchisa"); ///ZONA PENTRU TESTE
afisare (test6);*/
/*camasa a;
cin>>a;
cout<<a;*/
/*spalat test;
afisare(test);
spalatGreu test1;
afisare(test1);
stors test2;
afisare(test2);
uscat test3;
afisare (test3);*/
/* masina **v;
int n;
char s[30];
int i;
cout<<"Cate masini doriti?:"<<endl;
cout<<"(Numarul ales trebuie sa fie pozitiv)"<<endl;
int ok=0;
do
{
try{
cin>>s;
n=atoi(s);
if(n<=0){
throw(n);
}
ok=0;
}
catch(int n)
{
cout<<"NUMARUL trebuie sa fie POZITIV!"<<endl;
ok=1;
}
}while(ok);
v=new masina *[n];
for(i=0; i<n; i++) ///Generator de masini
{ ///Un multiplu de 4 va genera un rand de masini.
if(i%4==0)
{
v[i]=new spalat();
v[i]=dynamic_cast<spalat*>(v[i]);
}
if(i%4==1)
{
v[i]=new spalatGreu();
v[i]=dynamic_cast<spalatGreu*>(v[i]);
}
if(i%4==2)
{
v[i]=new stors();
v[i]=dynamic_cast<stors*>(v[i]);
}
if(i%4==3)
{
v[i]=new uscat();
v[i]=dynamic_cast<uscat*>(v[i]);
}
}
system("cls");
cout<<"Foarte bine! Avem urmatoarele masini: "<<endl<<endl;
for (i=0; i<n; i++)
{
cout<<typeid(*v[i]).name()<<' ';
}
Sleep(5000);
system("cls");
f.open("fisier.txt");
int nr;
char sir[30]; ///Tipul de haine
char col[30]; ///culoare
haine ***rufe;
f>>nr;
rufe= new haine **[nr];
int contor[nr]; ///nr de haine pentru fiecare angajat in parte.
haine ***curat;
haine *aux;
for(int i=0; i<nr; i++)
{
int elem;
f>>elem;
contor[i]=elem;
rufe[i]=new haine *[elem];
cout<<"CLIENTUL "<<i+1<<":"<<endl<<endl;
for(int j=0; j<elem; j++)
{
f>>sir;
f>>col;
cout<<sir<<" de culoare "<<col<<endl;
if(strcmp(sir,"camasa")==0) ///Citirea si alocarea unei matrici de tipuri de haine
{ ///Liniile reprezinta clientii si coloanele hainele acestora.
rufe[i][j]=new camasa(col);
rufe[i][j]=dynamic_cast<camasa*>(rufe[i][j]);
rufe[i][j]->setClient(i);
}
if(strcmp(sir,"rochie")==0)
{
rufe[i][j]=new rochie(col);
rufe[i][j]=dynamic_cast<rochie*>(rufe[i][j]);
rufe[i][j]->setClient(i);
}
if(strcmp(sir,"pantaloni")==0)
{
rufe[i][j]=new pantaloni(col);
rufe[i][j]=dynamic_cast<pantaloni*>(rufe[i][j]);
rufe[i][j]->setClient(i);
}
if(strcmp(sir,"costum")==0)
{
rufe[i][j]=new costum(col);
rufe[i][j]=dynamic_cast<costum*>(rufe[i][j]);
rufe[i][j]->setClient(i);
}
if(strcmp(sir,"geaca")==0)
{
rufe[i][j]=new geaca(col);
rufe[i][j]=dynamic_cast<geaca*>(rufe[i][j]);
rufe[i][j]->setClient(i);
}
if(strcmp(sir,"palton")==0)
{
rufe[i][j]=new palton(col);
rufe[i][j]=dynamic_cast<palton*>(rufe[i][j]);
rufe[i][j]->setClient(i);
}
}
}
curat= new haine **[nr];
for(int i=0; i<nr; i++)
{
curat[i]=new haine*[contor[i]];
}
Sleep(5000);
system("cls");
int etapa=1;
while(!eGol(*rufe,nr,contor[nr]))
{
cout<<"ETAPA "<<etapa<<":"<<endl;
Sleep(1000);
for(int i=0; i<nr; i++)
{
cout<<"CLIENT "<<i+1<<":"<<endl;
for(int j=0; j<contor[i]; j++)
{
for(int k=0; k<n; k++)
{
if(plasare(rufe[i][j],*v[k]))
{
/*proceseParcurse(*rufe[i][j]);*/ ///Preia hainele din matricea rufelor murdare formata mai sus.
/* cout<<endl<<"Adaugam in masina cu nr "<<k+1<<endl; ///cat timp aceasta nu este goala efectueaza cicluri de scoatere si
rufe[i][j]=new camasa("nedefinit"); /// depunere in alte masini ale rufelor
break;
}
}
for(int k=0; k<n; k++)
{
/// cout<<v[k]->getSpatiuOcupat()<<endl;
if(v[k]->getSpatiuOcupat()>(v[k]->getCapacitate())/2&&typeid(*v[k])!=typeid(uscat)) ///Muta hainele in masina urmatoare necesara
{
cout<<endl<<"Pornim masina cu nr "<<k+1<<endl;
for(int w=0; w<n; w++)
{
pornire(*v[k],*v[w]);
}
// cout<<endl<<"ATAT CU MASINA"<<endl;
}
if(v[k]->getSpatiuOcupat()>(v[k]->getCapacitate())/2&&typeid(*v[k])==typeid(uscat)) ///Atunci cand scoate haine din masina de uscat le calca si le scoate in matricea finala "Curat"
{
while((*v[k]).getNrHaine()>0)
{
aux=scoatere(*v[k]);
curat[(*aux).getClient()][contor[(*aux).getClient()]-1]=aux;
}
}
}
}
etapa++;
Sleep(5000);
system("cls");
}
}
for(int i=0; i<nr; i++)
{
float detergent=0;
float timp=0;
cout<<"Hainele clientului "<<i+1<<":"<<endl; ///Afisam elementele finale pentru fiecare client, impreuna cu totalul de timp petrecut in masini si de detergentul utilizat
for(int j=0; j<contor[i]; j++)
{
cout<<typeid(*curat[i][j]).name()<<endl;
proceseParcurse(*curat[i][j]);
detergent=detergent+((*curat[i][j]).getDetergent());
timp=timp+timpTotal(*curat[i][j]);
}
cout<<"Timp total comanda: "<<timp<<endl<<"Detergent utilizat: "<<detergent;
}
*/
camasa test("inchisa");
palton test2("inchisa");
palton test1=test2;
cout<<test<<endl<<endl<<test2<<endl<<endl<<test1;
return 0;
}
| true |
ff63b82055005986df751b1f40723bd3517cc5e6 | C++ | k-a-z-u/KLib | /test/streams/TestBuffer.cpp | UTF-8 | 3,245 | 2.703125 | 3 | [
"Apache-2.0"
] | permissive | /*
* TestBuffer.cpp
*
* Created on: Dec 18, 2013
* Author: kazu
*/
#ifdef WITH_TESTS
#include "../Test.h"
#include <cstdint>
#include "../../streams/Buffer.h"
using namespace K;
TEST(Buffer, insertByte) {
Buffer<uint8_t> buf;
for (unsigned int i = 0; i < 1024; ++i) {
buf.add((uint8_t) i);
}
ASSERT_EQ(1024, buf.getNumUsed());
uint8_t* ptr = buf.getData();
for (unsigned int i = 0; i < 1024; ++i) {
ASSERT_EQ((uint8_t)i, ptr[i]);
ASSERT_EQ((uint8_t)i, buf[i]);
}
}
TEST(Buffer, insertShort) {
Buffer<uint16_t> buf;
for (unsigned int i = 0; i < 1024; ++i) {
buf.add((uint16_t) i);
}
ASSERT_EQ(1024, buf.getNumUsed());
uint16_t* ptr = buf.getData();
for (unsigned int i = 0; i < 1024; ++i) {
ASSERT_EQ((uint16_t)i, ptr[i]);
ASSERT_EQ((uint16_t)i, buf[i]);
}
}
TEST(Buffer, insertDouble) {
Buffer<double> buf;
for (unsigned int i = 0; i < 1024; ++i) {
buf.add((double) i);
}
ASSERT_EQ(1024, buf.getNumUsed());
double* ptr = buf.getData();
for (unsigned int i = 0; i < 1024; ++i) {
ASSERT_EQ((double)i, ptr[i]);
ASSERT_EQ((double)i, buf[i]);
}
}
TEST(Buffer, remove) {
Buffer<int> buf;
buf.resize(16);
ASSERT_EQ(0, buf.getNumUsed());
ASSERT_EQ(16*sizeof(int), buf.getMemoryConsumption());
for (unsigned int i = 0; i < 16; ++i) {
buf[i] = i;
}
for (unsigned int i = 0; i < 16; ++i) {
ASSERT_EQ(i, buf[i]);
}
buf.setNumUsed(16);
ASSERT_EQ(16, buf.getNumUsed());
buf.remove(4);
ASSERT_EQ(16-4, buf.getNumUsed());
for (unsigned int i = 0; i < 16-4; ++i) {
ASSERT_EQ(i+4, buf[i]);
}
}
TEST(Buffer, insertRemove) {
Buffer<uint8_t> buf;
ASSERT_EQ(0, buf.getNumUsed());
for (unsigned int i = 0; i < 0xFFFF; ++i) {
uint8_t b = (uint8_t) i;
buf.add(b);
ASSERT_EQ(1, buf.getNumUsed());
ASSERT_EQ(b, buf.get());
ASSERT_EQ(0, buf.getNumUsed());
}
}
TEST(Buffer, insertRemove2) {
Buffer<uint8_t> buf;
ASSERT_EQ(0, buf.getNumUsed());
for (unsigned int i = 0; i < 0xFFFF; ++i) {
uint8_t b = (uint8_t) i;
buf.add(b); ASSERT_EQ(1, buf.getNumUsed());
buf.add(b); ASSERT_EQ(2, buf.getNumUsed());
buf.add(b); ASSERT_EQ(3, buf.getNumUsed());
ASSERT_EQ(b, buf.get()); ASSERT_EQ(2, buf.getNumUsed());
ASSERT_EQ(b, buf.get()); ASSERT_EQ(1, buf.getNumUsed());
ASSERT_EQ(b, buf.get()); ASSERT_EQ(0, buf.getNumUsed());
}
}
TEST(Buffer, insertRemove3) {
Buffer<uint8_t> buf;
ASSERT_EQ(0, buf.getNumUsed());
for (unsigned int i = 0; i < 0xFFFF; ++i) {
uint8_t b = (uint8_t) i;
buf.add(b); ASSERT_EQ(i+1, buf.getNumUsed());
}
for (unsigned int i = 0; i < 0xFFFF; ++i) {
uint8_t b = (uint8_t) i;
ASSERT_EQ(b, buf[i]);
}
// remove byte after byte and ensure the array operator works
unsigned int max = 0x4FFF;
unsigned int cnt = max;
for (unsigned int i = 3; i <= cnt; i+=3) {
buf.get();
buf.get();
buf.get();
for (unsigned int j = 0; j < max - i; ++j) {
uint8_t b = (uint8_t) (j+i);
ASSERT_EQ(b, buf[j]);
}
}
}
TEST(Buffer, sizeChange) {
Buffer<uint8_t> buf;
buf.add(123);
ASSERT_EQ(123, buf[0]);
ASSERT_EQ(1, buf.getNumUsed());
buf.setNumUsed(0);
ASSERT_EQ(0, buf.getNumUsed());
ASSERT_EQ(123, buf[0]);
buf.add(99);
ASSERT_EQ(1, buf.getNumUsed());
ASSERT_EQ(99, buf[0]);
}
#endif
| true |
7b6236543ac9b39c5ad3ecc5e7ad10bce3238e3c | C++ | rdnelson/Rainier_VM | /vm/Sub.cpp | UTF-8 | 717 | 2.53125 | 3 | [] | no_license | #include "Sub.h"
#include "VM.h"
#include "common/Opcode.h"
Sub::Sub(char* eip)
{
mEipOffset += LoadArgs(2, eip);
}
void Sub::Execute()
{
ResolveValue(1);
unsigned int val1;
unsigned int diff;
switch(subcode[0]) {
case SC_REG:
val1 = VM_INSTANCE()->GetRegister(arguments[0]);
diff = val1 - arguments[1];
VM_INSTANCE()->SetRegister(arguments[0], diff);
if(diff > val1)
VM_INSTANCE()->SetFlag(FLAG_OFL);
else
VM_INSTANCE()->ClearFlag(FLAG_OFL);
if(diff == 0)
VM_INSTANCE()->SetFlag(FLAG_ZERO);
else
VM_INSTANCE()->ClearFlag(FLAG_ZERO);
break;
default:
VM_INSTANCE()->GetLogger() << "Invalid First Operand For Sub: 0x" << std::hex << subcode[0] << std::dec << std::endl;
}
}
| true |
061ba88425babb07347cfe3e30ab0947176bedff | C++ | zigmundot/qt5dp-4-8 | /main.cpp | UTF-8 | 1,425 | 3.515625 | 4 | [] | no_license | #include <QCoreApplication>
/*
What
Smart pointers in the standard library
Description
Baked right into C++
Why
Just because Qt provides something doesn't mean its the best tool
Example
Test cases
unique_ptr - only one object can point to it
shared_ptr - multiple objects can point to it
https://www.geeksforgeeks.org/smart-pointers-cpp/
*/
#include <QDebug>
#include <iostream>
#include <memory>
#include "myclass.h"
using namespace std;
void testUnique()
{
qInfo() << "Testing Unique";
unique_ptr<MyClass> p1(new MyClass());
qInfo() << "p1=" << p1.get();
p1->test("From pointer 1");
unique_ptr<MyClass> p2 = move(p1); //take ownership
qInfo() << "p1=" << p1.get(); //set to nullptr
qInfo() << "p2=" << p2.get();
//Test the pointers
if(p1.get() != nullptr) p1->test("From pointer 1");
if(p2.get() != nullptr) p2->test("From pointer 2");
}
void testShared()
{
qInfo() << "Testing shared";
shared_ptr<MyClass> p1(new MyClass());
shared_ptr<MyClass> p2 = p1;
qInfo() << "p1=" << p1.get();
qInfo() << "p2=" << p2.get();
//Test the pointers
if(p1.get() != nullptr) p1->test("From pointer 1");
if(p2.get() != nullptr) p2->test("From pointer 2");
qInfo() << "Ref Count" << p1.use_count();
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//testUnique();
testShared();
return a.exec();
}
| true |
a4342b35340e2d289f1b85b28e598fd14cad7ea7 | C++ | mahudin/OpenGL-Alchemy | /Solution/mpgk/Wektor.cpp | UTF-8 | 3,751 | 3.21875 | 3 | [] | no_license | #pragma once
#include "Wektor.h"
Wektor::Wektor() {
wspolrzedne = new GLfloat[4];
for (int i = 0; i < 4; i++) {
wspolrzedne[i] = NULL;
}
}
Wektor::Wektor(GLfloat x) :Wektor() {
wspolrzedne[0] = x;
}
Wektor::Wektor(GLfloat x, GLfloat y, GLfloat z) : Wektor() {
wspolrzedne[0] = x;
wspolrzedne[1] = y;
wspolrzedne[2] = z;
}
Wektor::Wektor(GLfloat x, GLfloat y, GLfloat z, GLfloat w) : Wektor() {
wspolrzedne[0] = x;
wspolrzedne[1] = y;
wspolrzedne[2] = z;
wspolrzedne[3] = w;
}
Wektor::Wektor(GLfloat* tab) :Wektor() {
for (int i = 0; i < 4; i++) {
wspolrzedne[0] = tab[0];
}
}
void Wektor::setX(GLfloat x) {
wspolrzedne[0] = x;
}
void Wektor::setY(GLfloat y) {
wspolrzedne[1] = y;
}
void Wektor::setZ(GLfloat z) {
wspolrzedne[2] = z;
}
void Wektor::setW(GLfloat w) {
wspolrzedne[3] = w;
}
GLfloat Wektor::getX() const {
return wspolrzedne[0];
}
GLfloat Wektor::getY() const {
return wspolrzedne[1];
}
GLfloat Wektor::getZ() const {
return wspolrzedne[2];
}
GLfloat Wektor::getW() const {
return wspolrzedne[3];
}
Wektor Wektor::operator = (const Wektor& w) {
wspolrzedne[0] = w.getX();
wspolrzedne[1] = w.getY();
wspolrzedne[2] = w.getZ();
wspolrzedne[3] = w.getW();
return *this;
}
Wektor Wektor::operator + (const Wektor& w) {
Wektor n = Wektor();
n.setX(wspolrzedne[0] + w.getX());
n.setY(wspolrzedne[1] + w.getY());
n.setZ(wspolrzedne[2] + w.getZ());
n.setW(wspolrzedne[3] + w.getW());
return n;
}
Wektor Wektor::operator += (const Wektor& w) {
wspolrzedne[0] = wspolrzedne[0] + w.getX();
wspolrzedne[1] = wspolrzedne[1] + w.getY();
wspolrzedne[2] = wspolrzedne[2] + w.getZ();
wspolrzedne[3] = wspolrzedne[3] + w.getW();
return *this;
}
Wektor Wektor::operator - (const Wektor& w) {
Wektor n = Wektor();
n.setX(wspolrzedne[0] - w.getX());
n.setY(wspolrzedne[1] - w.getY());
n.setZ(wspolrzedne[2] - w.getZ());
n.setW(wspolrzedne[3] - w.getW());
return n;
}
Wektor Wektor::operator -= (const Wektor& w) {
wspolrzedne[0] = wspolrzedne[0] - w.getX();
wspolrzedne[1] = wspolrzedne[1] - w.getY();
wspolrzedne[2] = wspolrzedne[2] - w.getZ();
wspolrzedne[3] = wspolrzedne[3] - w.getW();
return *this;
}
Wektor Wektor::operator * (int l) {
Wektor n = Wektor();
n.setX(wspolrzedne[0] * l);
n.setY(wspolrzedne[1] * l);
n.setZ(wspolrzedne[2] * l);
n.setW(wspolrzedne[3] * l);
//std::cout << n << std::endl;
return n;
}
Wektor Wektor::operator *= (int l) {
wspolrzedne[0] = wspolrzedne[0] * l;
wspolrzedne[1] = wspolrzedne[1] * l;
wspolrzedne[2] = wspolrzedne[2] * l;
wspolrzedne[3] = wspolrzedne[3] * l;
return *this;
}
std::ostream& operator << (std::ostream& out, const Wektor& w) {
if (w.wspolrzedne[0]) {
out << "(" << w.wspolrzedne[0];
}
if (w.wspolrzedne[1]) {
out << ", " << w.wspolrzedne[1];
}
if (w.wspolrzedne[2] && w.wspolrzedne[3] == NULL) {
out << ", " << w.wspolrzedne[2] << ")";
} else {
out << ", " << w.wspolrzedne[2] << ", " << w.wspolrzedne[3] << ")";
}
return out;
}
Wektor Wektor::normalizuj() {
GLfloat dlugosc = std::sqrt(std::pow(wspolrzedne[0], 2) + std::pow(wspolrzedne[1], 2) + std::pow(wspolrzedne[2], 2));
Wektor w;
w.setX(wspolrzedne[0] / dlugosc);
w.setY(wspolrzedne[1] / dlugosc);
w.setZ(wspolrzedne[2] / dlugosc);
return w;
}
GLfloat Wektor::obliczSkalarny(const Wektor& w) {
return (this->wspolrzedne[0] * w.getX()) + (this->wspolrzedne[1] * w.getY()) + (this->wspolrzedne[2] * w.getZ()) + (this->wspolrzedne[3] * w.getW());
}
Wektor Wektor::obliczWektorowy(const Wektor& w) {
Wektor n;
n.setX(this->wspolrzedne[1] * w.getZ() - wspolrzedne[2] * w.getY());
n.setY(this->wspolrzedne[2] * w.getX() - wspolrzedne[0] * w.getZ());
n.setZ(this->wspolrzedne[0] * w.getY() - wspolrzedne[1] * w.getX());
return n;
} | true |
d656db6095b2c773c2a6eb63a9e79a40db0d55c3 | C++ | haklabo/TwinklebearDev-Lessons | /Lesson8/src/window.h | UTF-8 | 2,560 | 3.203125 | 3 | [
"MIT"
] | permissive | #ifndef WINDOW_H
#define WINDOW_H
#include <string>
#include <stdexcept>
#include <memory>
#include <SDL.h>
/**
* Window management class, provides a simple wrapper around
* the SDL_Window and SDL_Renderer functionalities
*/
class Window {
public:
//The constructor and destructor don't actually do anything as
//the class is pure static
Window();
~Window();
/**
* Initialize SDL, setup the window and renderer
* @param title The window title
*/
static void Init(std::string title = "Window");
///Quit SDL and destroy the window and renderer
static void Quit();
/**
* Draw a SDL_Texture to the screen at dstRect with various other options
* @param tex The SDL_Texture to draw
* @param dstRect The destination position and width/height to draw the texture with
* @param clip The clip to apply to the image, if desired
* @param angle The rotation angle to apply to the texture, default is 0
* @param xPivot The x coordinate of the pivot, relative to (0, 0) being center of dstRect
* @param yPivot The y coordinate of the pivot, relative to (0, 0) being center of dstRect
* @param flip The flip to apply to the image, default is none
*/
static void Draw(SDL_Texture *tex, SDL_Rect &dstRect, SDL_Rect *clip = NULL,
float angle = 0.0, int xPivot = 0, int yPivot = 0,
SDL_RendererFlip flip = SDL_FLIP_NONE);
/**
* Loads an image directly to texture using SDL_image's
* built in function IMG_LoadTexture
* @param file The image file to load
* @return SDL_Texture* to the loaded texture
*/
static SDL_Texture* LoadImage(const std::string &file);
/**
* Generate a texture containing the message we want to display
* @param message The message we want to display
* @param fontFile The font we want to use to render the text
* @param color The color we want the text to be
* @param fontSize The size we want the font to be
* @return An SDL_Texture* to the rendered message
*/
static SDL_Texture* RenderText(const std::string &message, const std::string &fontFile, SDL_Color color, int fontSize);
///Clear the renderer
static void Clear();
///Present the renderer, ie. update screen
static void Present();
///Get the window's box
static SDL_Rect Box();
private:
static std::unique_ptr<SDL_Window, void (*)(SDL_Window*)> mWindow;
static std::unique_ptr<SDL_Renderer, void (*)(SDL_Renderer*)> mRenderer;
static SDL_Rect mBox;
};
#endif | true |
36e2ed78613a16743e64b8b0727848a41e574e78 | C++ | YellowHCH/cmake_practice | /template/sub1/include/myMemoryPool.h | UTF-8 | 3,961 | 3.578125 | 4 | [] | no_license | /*
设计内存池若干
先设计一个固定对象大小的
*/
#ifndef MY_MEMORYPOOL_H
#define MY_MEMORYPOOL_H
#include <stdlib.h>
#include <iostream>
#include <list>
int unit = 0;
int block = 0;
// 固定大小内存池设计
/*
内存池数据结构,基本结构是内存单元unit,内存块block包含块信息和内存单元,由内存池去调用内存块
*/
// 内存块
class myMemoryBlock{
public:
myMemoryBlock() : numFree(numUnit) , nFirst(0), pNext(nullptr)//, objSize(sizeof(myMemoryBlock))
{
//std::cout << "this is constructor " << std::endl;
// 调用内存块初始化函数给内存单元的后继单元编号赋值
InitMemoryBlock();
}
~myMemoryBlock(){
//std::cout << "this is destructor " << std::endl;
}
// 重载operator new,为内存单元也分配内存,输入的参数只能是size_t类型
static void* operator new( size_t){
//std::cout << "this is overload new, sizeof memory is " << sizeof(myMemoryBlock) + numUnit*(unitSize + 2) << std::endl;
//return malloc(sizeof(myMemoryBlock) + size_t(numUnit_)*(size_t(unitSize_) + 4));
return ::operator new(sizeof(myMemoryBlock) + numUnit*(unitSize + 2));
}
static void operator delete(void *p, size_t){
//free(p);
//std::cout << "this is overload destructor " << std::endl;
::operator delete (p);
}
// 没有用的函数,测试内存块时打印的信息
void printInfo(){
std::cout << "addr of numUnit is " << &numUnit << std::endl;
std::cout << "addr of unitSize is " << &unitSize << std::endl;
std::cout << "addr of numFree is " << &numFree << std::endl;
std::cout << "addr of nFirst is " << &nFirst << std::endl;
std::cout << "addr of pNext is " << (void*)&pNext << std::endl;
//std::cout << "addr of objSize is " << (void*)&objSize << std::endl;
std::cout << "addr of unitSeg is " << (void*)&unitSeg << std::endl;
std::cout << "size of pointer is " << sizeof(std::nullptr_t) << std::endl;
}
private:
// 初始化内存块
void InitMemoryBlock();
public:
static uint numUnit; // 内存块中内存单元数量
static uint unitSize; // 内存单元size,是被存储对象的大小加上4个字节,4字节记录下一个空闲单元编号,这里用4个字节有点浪费,先这么写
uint numFree; // 空闲的内存单元数量
uint nFirst; // 第一个空闲内存单元编号,编号从0开始
myMemoryBlock * pNext; // 指向下一个内存块
//uint objSize; // 因为内存对齐的原因,对象的size有点迷,在计算单元的起始位置时需要用到对象大小
char unitSeg; // 作为内存块信息头部与内存单元的分割点
};
uint myMemoryBlock::numUnit = 4;
uint myMemoryBlock::unitSize = 4;
// 内存池
template<typename T>
class myMemoryPool{
public:
myMemoryPool(uint numUint_ = 4) : objSize(sizeof(T)), numBlocks(0) ,
numUnit(numUint_), blockSize((objSize+2)*numUint_ + sizeof(myMemoryBlock)){
//myMemoryBlock::numUnit = numUint_;
//myMemoryBlock::unitSize = objSize;
// 内存池初始化时创建5个内存块
for(int i = 0; i < 4; ++i)
creatBlock();
}
~myMemoryPool();
// 从内存池获得一个固定大小对象内存空间,返回内存地址
T* getMemory();
// 从内存池归还内存单元
bool returnMemory(T* ptr);
private:
// 创建新的内存块,并添加到blocks_中
myMemoryBlock* creatBlock();
private:
uint objSize; // 对象大小
uint numBlocks; // 内存块数量,初始化为0
uint numUnit; // 内存块中单元数量
size_t blockSize; // 内存块大小
std::list<myMemoryBlock*> blocks_; // 内存块链表
};
void test_mymemorypool();
#endif // MY_MEMORYPOOL_H
| true |
78bb7a8f072321edfb25990255f7120ddf3baee2 | C++ | Redwanuzzaman/Online-Judge-Problem-Solutions | /Codeforces/Find Square.cpp | UTF-8 | 458 | 2.75 | 3 | [] | no_license | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m, cnt = 0, row = 0, col = 0;
string s;
cin >> n >> m;
for(int i = 0; i < n; i++)
{
cin >> s;
for(int j = 0; j < m; j++)
{
if(s[j] == 'B')
{
cnt++;
row += i+1;
col += j+1;
}
}
}
row /= cnt;
col /= cnt;
cout << row << " " << col << endl;
}
| true |
26b0531690229cc3bc6ff057c66ec1b6bbf81ae4 | C++ | tpetrina/rp1 | /2013/3/cetverokut/c-test3.cpp | UTF-8 | 746 | 2.671875 | 3 | [] | no_license | #include <iostream>
#include <utility>
#include <string>
#include <set>
#include "cetverokut.h"
using namespace std;
typedef std::pair<double,double> tocka;
int main()
{
// testiramo tipCetverokuta
tocka A(-1,0), B(0,0.5773497), C(1,0), D(0,-0.5773497);
tocka A2(-1,0), B2(0,1), C2(1,0), D2(0,-1);
bool uvjet = true;
Cetverokut c1(A,B,C,D);
if( c1.tipCetverokuta() != string("trapez") ) uvjet = false;
Trapez t2(A2,B2,C2,D2);
if( t2.tipCetverokuta() != string("kvadrat") ) uvjet = false;
Pravokutnik p1(A2,B2,C2,D2);
if( p1.tipCetverokuta() != string("kvadrat") ) uvjet = false;
if( uvjet ) cout << "Ispravno" << endl;
return 0;
}
| true |
c0fdf35c898f5d165a195bd38a7ab035177efff0 | C++ | vdelgadov/itcvideogame | /Stable/Behaviours/Skirk.cpp | UTF-8 | 3,163 | 2.71875 | 3 | [] | no_license | #ifndef _SKIRK
#define _SKIRK
#include "Actor_States.cpp"
//InfluenceMap* AIController::s_InfluenceMap;
class SkirkEngaging : public AState<Actor> {
private:
static const double attacking_range;
public:
void enter(Actor* a){
cout << "Entering Skirk Engaging" <<endl;
//Enemy = a->getController()->getEnemy();//Engine.getClosestOrWhatever()...
}
void execute(Actor* a){
AIController* aic = (AIController*)(a->getController());
CObject* Enemy = aic->getEnemy(); //...
if(!Enemy){
a->getFSM()->changeState("Idle");
return;
}
int x, y;
getBestPosition(a, &x, &y);
int m_x, m_y;
AIController::s_InfluenceMap->mapCoords(a->getVehicle()->getPos(), &m_x, &m_y);
double real_x = (x+0.5)*(/*Engine.getWidth()*/ 100.0 / AIController::s_InfluenceMap->getMapWidth());
double real_y = (y+0.5)*(/*Engine.getWidth()*/ 100.0 / AIController::s_InfluenceMap->getMapHeight());
Vector3D stf;
if(abs(m_x - x) < a->getController()->getInfluenceRadius() || abs(m_y - y) < a->getController()->getInfluenceRadius()){
stf = SteeringBehaviors<Vector3D>::pursuit(a->getVehicle(), Enemy->getVehicle());
stf += SteeringBehaviors<Vector3D>::seek(Vector3D(real_x, real_y, a->getVehicle()->getPos().z), a->getVehicle());
if((a->getVehicle()->getPos() - Enemy->getVehicle()->getPos()).magnitude() < attacking_range){
a->getFSM()->changeState("Attack");
return;
}
}else{
stf = SteeringBehaviors<Vector3D>::evade(a->getVehicle(), Enemy->getVehicle());
}
stf += a->getVehicle()->getCurrVel();
stf.normalize();
a->getVehicle()->setCurrVel(stf);
}
void exit(Actor* a){
cout << "Exiting Skirk Engaging" << endl;
}
void getBestPosition(Actor* a, int* x, int* y){
int a_x, a_y;
AIController::s_InfluenceMap->mapCoords(a->getVehicle()->getPos(), &a_x, &a_y);
*x = a_x;
*y = a_y;
int vr = a->getViewRadius();
int up, down, left, right;
up = a_y-vr;
down = a_y+vr;
left = a_x-vr;
right = a_x+vr;
while(down >= AIController::s_InfluenceMap->getMapHeight())
down--;
while(up< 0)
up++;
while(left < 0)
left++;
while(right >= AIController::s_InfluenceMap->getMapWidth())
right--;
for(int i=up; i<=down; i++)
for(int j=left; j<=right; j++){
if(AIController::s_InfluenceMap->getSpot(i, j) > AIController::s_InfluenceMap->getSpot(*y, *x)){
*x = j;
*y = i;
}
}
}
};
const double SkirkEngaging::attacking_range = 1.5;
class SkirkAttack : public AState<Actor> {
void enter(Actor* a){
cout << "Entering Skirk Attack" << endl;
}
void execute(Actor* a){
AIController* aic = (AIController*)(a->getController());
CObject* Enemy = aic->getEnemy();
Vector3D stf = SteeringBehaviors<Vector3D>::pursuit(a->getVehicle(), Enemy->getVehicle());
stf.normalize();
a->getVehicle()->setCurrVel(stf*(a->getVehicle()->getMaxSpeed()+0.2));
cout << "Chargin >> " << endl;
a->getFSM()->changeState("Engaging");
}
void exit(Actor* a){
cout << "Exiting Skirk Attack" << endl;
}
};
#endif | true |
99ec3e2c66042c2be932af3fb30dda219503eb81 | C++ | soqutto/practice | /cheetah/3-5.cpp | UTF-8 | 481 | 3.0625 | 3 | [] | no_license | #include <bits/stdc++.h>
using namespace std;
void countStrings(vector<string> s);
void countStrings(vector<string> s){
map<string, int> m;
for(int i = 0; i < s.size(); ++i){
m[s[i]]++;
}
map<string, int>::iterator it = m.begin();
while(it != m.end()){
cout << (*it).first << "" << (*it).second << endl;
++it;
}
}
int main(){
vector<string> s = {"abc", "def", "abc", "st", "st", "st"};
countStrings(s);
return 0;
}
| true |
a4a05e3c7adec443f00d6dc5bdc4d5739c24d009 | C++ | anonyxhappie/CodeChef | /begginer/cielrcpt.cpp | UTF-8 | 393 | 2.90625 | 3 | [] | no_license | #include <iostream>
using namespace std;
int two(int);
int main(){
freopen("in.txt", "r", stdin);
int t, a;
cin >> t;
while(t--){
cin >> a;
cout << two(a) << endl;
}
return 0;
}
int two(int n){
int at[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};
int i=11, count=0;
while(n){
if(n>=at[i]){
count+=n/at[i];
n%=at[i];
} else{
i--;
}
}
return count;
}
| true |
06d34901d41317f3e62a1c7e9667904ed5beabc1 | C++ | quincinia/school | /cs302/projects/Art Gallery Extra Credit/include/vertex.h | UTF-8 | 1,324 | 3.0625 | 3 | [] | no_license | #ifndef VERTEX_H
#define VERTEX_H
#include <iostream>
#include <vector>
#include <string>
class Edge;
class Vertex
{
friend class DCELVertex;
public:
//Used to generate unique vertex names
static int count;
std::string name;
Vertex(float x, float y);
~Vertex(); //all memory is handled by the Mesh class
//Sets edge helper to this
void help(Edge* e);
//Looks through the edge record and determines if this
//vertex can help any of them
Edge* findHelper(std::vector<Edge*>);
float x() const {return X;};
float y() const {return Y;};
char type() const {return Type;};
//Used in ::classifyVertices
void setType(char);
//Collection of all vertices this vertex shares an edge with
std::vector<Vertex*> partners;
//Clockwise next
Vertex* next = nullptr;
//CCW prev
Vertex* prev = nullptr;
Edge* helper = nullptr;
Edge* nextEdge = nullptr; //used in makeMonotone
int color;
friend std::ostream& operator<<(std::ostream&, const Vertex&);
private:
float X, Y;
char Type;
//5 types
// b - start
// s - split
// e - end
// m - merge
// r - regular/normal
//Determines if the vertex has a left neighbor
//at the same y-value
bool hasHorizontalLeft();
//To only be used with regular vertices
bool hasLeftInterior();
};
#endif // VERTEX_H
| true |
f0ae4df7df92e8a39c409b84fb162c076fe54cde | C++ | whztt07/acm | /project_euler/11/Sov_05_10_2012.cpp | UTF-8 | 1,311 | 2.859375 | 3 | [] | no_license | #include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int matrix[20][20];
int n = 20;
bool ok(int x, int y) {
return (x>=0&&x<n && y>=0&&y<n);
}
int main() {
for (int i = 0; i < n; ++ i)
for (int j = 0; j < n; ++ j)
cin >> matrix[i][j];
int ans = -1;
for (int i = 0; i < n; ++ i)
for (int j = 0; j < n; ++ j)
{
if (ok(i+3,j))
{
int cur = 1;
for (int k = 0; k < 4; ++ k)
cur *= matrix[i+k][j];
ans = max(ans, cur);
}
if (ok(i,j+3))
{
int cur = 1;
for (int k = 0; k < 4; ++ k)
cur *= matrix[i][j+k];
ans = max(ans, cur);
}
if (ok(i+3,j+3))
{
int cur = 1;
for (int k = 0; k < 4; ++ k)
cur *= matrix[i+k][j+k];
ans = max(ans, cur);
}
if (ok(i-3,j+3))
{
int cur = 1;
for (int k = 0; k < 4; ++ k)
cur *= matrix[i-k][j+k];
ans = max(ans, cur);
}
}
cout << ans << endl;
return 0;
}
| true |
ed6a29b3e857cccc455df2845026a4deeab752b4 | C++ | ms13r/C- | /List Data Structure/List.hpp | UTF-8 | 9,961 | 3.640625 | 4 | [] | no_license | // The following code was done by Miroslav Sanader.
// Functions are also adapted from Dietel.
// Data Structures; Myers
template <typename T>
List<T>::const_iterator::const_iterator(){ // default zero parameter constructor
current = nullptr;
}
template <typename T>
T & List<T>::const_iterator::retrieve() const{
return (current->data);
}
template <typename T>
List<T>::const_iterator::const_iterator(Node *p) : current(p) {
}
template <typename T>
const T & List<T>::const_iterator::operator*() const{ // operator*() to return element
return retrieve();
}
template <typename T>
// increment/decrement operators
typename List<T>::const_iterator & List<T>::const_iterator::operator++(){
current = current->next;
return *this;
}
template <typename T>
typename List<T>::const_iterator List<T>::const_iterator::operator++(int){
const_iterator oldIter = *this;
++(*this);
return oldIter;
}
template <typename T>
typename List<T>::const_iterator & List<T>::const_iterator::operator--(){
current = current->prev;
return *this;
}
template <typename T>
typename List<T>::const_iterator List<T>::const_iterator::operator--(int){
const_iterator oldIter = *this;
--(*this);
return oldIter;
}
// comparison operators
template <typename T>
bool List<T>::const_iterator::operator==(const const_iterator &rhs) const{
if(current == rhs.current)
return true;
else
return false;
}
template <typename T>
bool List<T>::const_iterator::operator!=(const const_iterator &rhs) const{
return !(*this == rhs);
}
/*Begin the iterator class that allows for data to be changed*/
template <typename T>
List<T>::iterator::iterator(){
}
template <typename T>
List<T>::iterator::iterator(Node *p) : const_iterator(p){
}
template <typename T>
T & List<T>::iterator::operator*(){
return const_iterator::retrieve();
}
template <typename T>
const T & List<T>::iterator::operator*() const{
return const_iterator::operator*();
}
// increment/decrement operators
template <typename T>
typename List<T>::iterator & List<T>::iterator::operator++(){
this->current = this->current->next;
return *this;
}
template <typename T>
typename List<T>::iterator List<T>::iterator::operator++(int){
iterator oldItr = *this;
++(*this);
return oldItr;
}
template <typename T>
typename List<T>::iterator & List<T>::iterator::operator--(){
this->current = this->current->prev;
return *this;
}
template <typename T>
typename List<T>::iterator List<T>::iterator::operator--(int){
iterator oldItr = *this;
--(*this);
return oldItr;
}
/*_______________________________________________________________________*/
template <typename T>
List<T>::List(){ // default zero parameter constructor
init();
}
template <typename T>
List<T>::List(const List &rhs){ // copy constructor
init();
for(auto & incrementer: rhs) // For each element in rhs, add it to the new list
push_back(incrementer);
}
template <typename T>
List<T>::List(List && rhs) : theSize{rhs.theSize}, head{rhs.head}, tail{rhs.tail}{ // move constructor
rhs.theSize = 0;
rhs.head = nullptr;
rhs.tail = nullptr;
}
// num elements with value of val
template <typename T>
List<T>::List(int num, const T& val){
init();
for(int i = 0; i < num; i++)
push_back(val);
}
// constructs with elements [start, end)
template <typename T>
List<T>::List(const_iterator start, const_iterator end){
init();
for(const_iterator i = start; i != end; i++)
push_back(*i);
}
// constructs with a copy of each of the elements in the initalizer_list
template <typename T>
List<T>::List(std::initializer_list<T> iList){
init();
for(auto & iter: iList)
push_back(iter);
}
template <typename T>
List<T>::~List(){ // destructor
clear();
delete tail;
delete head;
}
// copy assignment operator
template <typename T>
const List<T>& List<T>::operator=(const List &rhs){
List<T> tempCopy = rhs; // Make temporary copy
std::swap(*this, tempCopy); // Swap resources (no longer care about calling object's info)
return *this; // Return calling object, and allow for old resources to be deleted
}
// move assignment operator
template <typename T>
List<T> & List<T>::operator=(List && rhs){
std::swap(theSize, rhs.theSize);
std::swap(head, rhs.head);
std::swap(tail, rhs.tail);
return *this;
}
// sets list to the elements of the initializer_list
template <typename T>
List<T>& List<T>::operator= (std::initializer_list<T> iList){
List<T> temp(iList);
std::swap(*this, temp);
}
template <typename T>
int List<T>::size() const{ // number of elements
return theSize;
}
template <typename T>
bool List<T>::empty() const{ // check if list is empty
if(theSize == 0)
return true;
else
return false;
}
template <typename T>
void List<T>::clear(){ // delete all elements
while(!empty())
pop_front();
}
template <typename T>
void List<T>::reverse(){ // reverse the order of the elements
Node * itr = tail; // Begin at the end of the List
while(itr != head){ // While not the first element of the list
std::swap(itr->next, itr->prev); // Swap the pointers; previous is now next, and next is now previous
itr = itr->next; // Move to the previous node
}
std::swap(head, tail);
}
template <typename T>
T& List<T>::front(){ // reference to the first element
return *begin();
}
template <typename T>
const T& List<T>::front() const{
return *begin();
}
template <typename T>
T& List<T>::back(){ // reference to the last element
return *--end();
}
template <typename T>
const T& List<T>::back() const{
return *--end(); // Return the last element
}
template <typename T>
void List<T>::push_front(const T & val){ // insert to the beginning
insert(begin(), val);
}
template <typename T>
void List<T>::push_front(T && val){ // move version of insert
insert(begin(), std::move(val));
}
template <typename T>
void List<T>::push_back(const T & val){ // insert to the end
insert(end(), val);
}
template <typename T>
void List<T>::push_back(T && val){ // move version of insert
insert(end(), std::move(val));
}
template <typename T>
void List<T>::pop_front(){ // delete first element
erase( begin() );
}
template <typename T>
void List<T>::pop_back(){ // delete last element
erase( --end() );
}
template <typename T>
void List<T>::remove(const T &val){ // remove all elements with value = val
iterator remover = begin();
for(remover; remover != end(); remover++){
if(*remover == val){ // If the value of what you are looking for is found, erase it using erase func
erase(remover);
}
}
}
template <typename T>
template <typename PREDICATE>
void List<T>::remove_if(PREDICATE pred){ // remove all elements for which Predicate pred is true
for(auto remover = begin(); remover != end(); remover++)
if(pred(*remover) == true) // If the predicate is true, erase the element (same as remove)
erase(remover);
}
// print out all elements. ofc is deliminitor
template <typename T>
void List<T>::print(std::ostream& os, char ofc) const{
const_iterator iter = begin();
for(iter; iter != end(); iter++){
os << *iter << ofc;
}
}
template <typename T>
typename List<T>::iterator List<T>::begin(){ // iterator to first element
return (head->next);
}
template <typename T>
typename List<T>::const_iterator List<T>::begin() const{
return (head->next);
}
template <typename T>
typename List<T>::iterator List<T>::end(){ // end marker iterator
return (tail);
}
template <typename T>
typename List<T>::const_iterator List<T>::end() const{
return (tail);
}
template <typename T>
typename List<T>::iterator List<T>::insert(iterator itr, const T& val){ // insert val ahead of itr
Node * n = itr.current;
theSize++;
return (n->prev = n->prev->next = new Node(val, n->prev, n));
}
template <typename T>
typename List<T>::iterator List<T>::insert(iterator itr, T && val){ // move version of insert
Node * n = itr.current;
theSize++;
return (n->prev = n->prev->next = new Node(std::move(val), n->prev, n));
}
template <typename T>
typename List<T>::iterator List<T>::erase(iterator itr){ // erase one element
Node *p = itr.current;
iterator retVal{ p->next };
p->prev->next = p->next;
p->next->prev = p->prev;
delete p;
theSize--;
return retVal;
}
template <typename T>
typename List<T>::iterator List<T>::erase(iterator start, iterator end){ // erase [start, end)
for(iterator itr = start; itr != end; )
itr = erase(itr);
return end;
}
template <typename T>
void List<T>::init(){
theSize = 0;
head = new Node; // Construct a new node with nullptrs
tail = new Node;
head->next = tail; // Makes head ptr point to the end
tail->prev = head; // Makes tail ptr point back to the beginning
}
/*___________________________________________________________*/
/*Operator overloading is done here*/
// overloading comparison operators
template <typename T>
bool operator==(const List<T> & lhs, const List<T> &rhs){
if(lhs.size() != rhs.size()) // If the size of the lists isn't equal, they can't be the same!
return false;
else{
auto itr1 = lhs.begin();
auto itr2 = rhs.begin();
for(itr1; itr1 != lhs.end(); itr1++){
if(*itr1 != *itr2){ // If the two contents aren't the same
return false;
}
itr2++; // Make sure second iterator is incremented
}
}
return true;
}
template <typename T>
bool operator!=(const List<T> & lhs, const List<T> &rhs){
return !(lhs == rhs);
}
// overloading output operator
template <typename T>
std::ostream & operator<<(std::ostream &os, const List<T> &l){
l.print(os);
return os;
}
| true |
625c3f0c5394732dfa13749e2da11c9d98358117 | C++ | Rockroyal305/Practice-Problems | /The Game of Life.cpp | UTF-8 | 2,459 | 2.921875 | 3 | [] | no_license | #include <iostream>
using namespace std;
int main()
{
int tests;
cin >> tests;
for(int t = 0; t < tests; t++)
{
int number, iterations, dead = 0;
char cells[1000], new_cells[1000], previous_cells[1000];
cin >> number >> iterations;
for(int i = 0; i < number; i++)
{
cin >> cells[i];
if(cells[i] == '0')
dead++;
//cout << cells[i];
}
//cout << endl;
//cout << iterations << endl;
if(dead < number)
{
for(int i = 0; i < iterations; i++)
{
bool is_previous = true;
for(int j = 0; j < number; j++)
previous_cells[i] = cells[i];
for(int j = 0; j < number; j++)
{
if(j == 0)
{
if(cells[j+1] == '1' ||
cells[j] == '1')
new_cells[j] = '1';
else
new_cells[j] = '0';
}
else if(j == number-1)
{
if(cells[j-1] == '1' ||
cells[j] == '1')
new_cells[j] = '1';
else
new_cells[j] = '0';
}
else
{
if(cells[j] == '1' ||
((cells[j-1] == '1' && cells[j+1] == '0') ||
(cells[j+1] == '1' && cells[j-1] == '0')))
new_cells[j] = '1';
else
new_cells[j] = '0';
}
}
//bool is_previous = true;
/*for(int j = 0; j < number; j++)
{
cells[j] = new_cells[j];
cout << cells[j];
if(previous_cells[j] != cells[j])
is_previous = false;
}
cout << endl;*/
if(is_previous == true)
break;
}
}
for(int i = 0; i < number; i++)
{
cout << cells[i];
}
cout << endl;
}
}
| true |
4977d722f7fd9d588f3d9cd2d6e179ff72962873 | C++ | iosiginer/Reversi | /ClassicLogic.h | UTF-8 | 1,615 | 3.171875 | 3 | [] | no_license | #ifndef REVERSI_CLASSICLOGIC_H
#define REVERSI_CLASSICLOGIC_H
#include "GameLogic.h"
/**
* The classic set of rules for the Reversi Game. It inherits from GameLogic, to make it more easy to find.
*/
class ClassicLogic : public GameLogic {
private:
/**
* Get the directions in which the Player should check for possible Moves.
* @return vector<Coordinate *> the list of possible directions to move.
*/
virtual vector<Coordinate *> getDirections(Coordinate, Player *, int *, Board *) const;
/**
* Checks whether the direction is valid. It runs toward the desired direction and checks it as a Turing Machine.
* @return bool - true only if the direction gives any gains for the Move.
*/
bool validDirection(Coordinate *, Player *, Coordinate *, int *, Board *) const;
public:
/**
* Constructor for ClassicLogic.
*/
ClassicLogic();
/**
* Returns a Move instantation with the Coordinate in arguments as position.
* @param pos - the wanted position for the Move.
* @param player - the current playing player.
* @param board - the current board.
* @return Move - the move, ready to be used.
*/
virtual Move *getMoveByPosition(Coordinate *pos, Player *player, Board *board);
/**
* Analizes each empty cell and finds all the possible moves for the Player.
* @return vector<Move *> - the list of possible moves for the Player.
*/
virtual vector<Move *> getPossibleMoves(Player *, Board *) const;
/**
* Destructor.
*/
~ClassicLogic() {}
};
#endif //REVERSI_CLASSICLOGIC_H
| true |
6bd07f74237bf2f38bc30b7cc537d7e688e88908 | C++ | Tanjim131/Problem-Solving | /UVa/598.cpp | UTF-8 | 3,743 | 3.203125 | 3 | [] | no_license | #include <iostream>
#include <limits>
#include <vector>
#include <sstream>
#include <string>
// will not if there are multiple newspapers with the same name
void combination(const std::vector<std::string> &newspapers, std::vector <std::string> current_subset, int target_subset_size, int index = 0){
// at each index, we can either take the current newspaper or leave it
if(current_subset.size() == target_subset_size){
// print the solution
for(int i = 0 ; i < current_subset.size() ; ++i){
std::cout << current_subset[i];
if(i != current_subset.size() - 1) std::cout << ", ";
}
std::cout << '\n';
return;
}
if(index == newspapers.size()) return; // order of checking is important
// when we go past the last index, we may have a valid solution at our hand
// so checking the solution condition early is necessary
//std::cout << "at index " << index << " taking " << newspapers[index] << '\n';
current_subset.emplace_back(newspapers[index]);
combination(newspapers, current_subset, target_subset_size, index + 1);
//std::cout << "at index " << index << " leaving " << newspapers[index] << '\n';
current_subset.pop_back();
combination(newspapers, current_subset, target_subset_size, index + 1);
}
// doesn't print in lexicographical order
// void combination_iterative(const std::vector<std::string> &newspapers, int target_subset_size){
// int newspaper_number = newspapers.size();
// int len = 1 << newspaper_number;
// for(int i = 0 ; i < len ; ++i){
// int number_of_set_bits = __builtin_popcount(i);
// if(number_of_set_bits == target_subset_size){
// for(int j = 0 ; j < newspaper_number ; ++j){
// if(i & (1 << j)){
// std::cout << newspapers[j] << ", ";
// }
// }
// std::cout << '\n';
// }
// }
// }
void printSolution(const std::vector <std::string> &newspapers, int start, int end){
int target_subset_size = start;
do{
std::cout << "Size " << target_subset_size << '\n';
combination(newspapers, std::vector <std::string>(), target_subset_size);
std::cout << '\n';
++target_subset_size;
} while(target_subset_size <= end); // when printing only a single "target_subset_size", end == -1
// using do_while does the job
}
void parseToken(const std::string &first_line, std::string &token1, std::string &token2){
std::istringstream iss(first_line);
iss >> token1 >> token2;
}
int main(int argc, char const *argv[])
{
int M;
std::cin >> M;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // ignore '\n' left in the buffer by std::cin
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // consume unnecessary blank line
std::string first_line;
for(int i = 0 ; i < M ; ++i){
std::getline(std::cin, first_line);
std::string token1, token2;
parseToken(first_line, token1, token2);
std::vector <std::string> newspapers;
std::string newspaper;
while(std::getline(std::cin, newspaper)){
if(newspaper.empty()) break;
newspapers.emplace_back(newspaper);
}
int start = 1, end = newspapers.size();
if(token1 != "*") {
start = std::stoi(token1);
if(!token2.empty()) end = std::stoi(token2);
else end = -1;
}
if(i > 0) std::cout << '\n';
printSolution(newspapers, start, end);
}
return 0;
}
| true |
9439136f151336ee3a745b0e5afc4ad36fa3e74e | C++ | ptitzlabs/nyancodec | /include/console_color.hpp | UTF-8 | 2,873 | 2.71875 | 3 | [] | no_license | #ifndef CONSOLE_COLOR_HPP
#define CONSOLE_COLOR_HPP
#pragma once
#include <iostream>
#ifdef __linux__
#define RESET "\033[0m"
#define BLACK "\033[30m" /* Black */
#define RED "\033[31m" /* Red */
#define GREEN "\033[32m" /* Green */
#define YELLOW "\033[33m" /* Yellow */
#define BLUE "\033[34m" /* Blue */
#define MAGENTA "\033[35m" /* Magenta */
#define CYAN "\033[36m" /* Cyan */
#define WHITE "\033[37m" /* White */
#define BLACKBG "\033[40m" /* Black */
#define REDBG "\033[41m" /* Red */
#define GREENBG "\033[42m" /* Green */
#define YELLOWBG "\033[43m" /* Yellow */
#define BLUEBG "\033[44m" /* Blue */
#define MAGENTABG "\033[45m" /* Magenta */
#define CYANBG "\033[46m" /* Cyan */
#define WHITEBG "\033[47m" /* White */
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
#define CLEARLINE "\x1b[K"
#define BLACKONWHITE "\033[40m\033[37m"
#elif _WIN32
#include <windows.h>
inline std::ostream& BLUE(std::ostream &s)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout, FOREGROUND_BLUE
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
return s;
}
inline std::ostream& RED(std::ostream &s)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout,
FOREGROUND_RED|FOREGROUND_INTENSITY);
return s;
}
inline std::ostream& GREEN(std::ostream &s)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout,
FOREGROUND_GREEN|FOREGROUND_INTENSITY);
return s;
}
inline std::ostream& YELLOW(std::ostream &s)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout,
FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
return s;
}
inline std::ostream& WHITE(std::ostream &s)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout,
FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
return s;
}
struct color {
color(WORD attribute):m_color(attribute){}
WORD m_color;
};
template <class _Elem, class _Traits>
std::basic_ostream<_Elem,_Traits>&
operator<<(std::basic_ostream<_Elem,_Traits>& i, color& c)
{
HANDLE hStdout=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout,c.m_color);
return i;
}
#endif
#endif // CONSOLE_COLOR_HPP
| true |
bfadcf7aaf627aaa5acd2035d4acf9327e72dc1e | C++ | renishalachhani/Practicas_AEDA_19-20 | /prac7_Renisha/nodoAVL.h | UTF-8 | 760 | 2.625 | 3 | [] | no_license | #pragma once
#include <iostream>
#include "dni.h"
using namespace std;
template <class Clave>
class nodoAVL {
private:
Clave clave_;
int bal_;
nodoAVL *izdo_;
nodoAVL *dcho_;
public:
inline nodoAVL(Clave clave, nodoAVL<Clave> *izq=NULL, nodoAVL<Clave> *der=NULL): bal_(0), clave_(clave), izdo_(izq), dcho_(der){}
inline ~nodoAVL(){}
inline nodoAVL<Clave>*& get_izq() {return izdo_;}
inline nodoAVL<Clave>*& get_dcho() {return dcho_;}
inline Clave get_clave() {return clave_;}
inline int get_bal() {return bal_;}
inline void set_izq(nodoAVL<Clave>* nodo) {izdo_=nodo;}
inline void set_dcho(nodoAVL<Clave>* nodo) {dcho_=nodo;}
inline void set_bal(int bal) {bal_=bal;}
inline void set_clave(Clave clave) {clave_=clave;}
}; | true |
c3f74ed07168fd35d96140f4a14bce1a31fa5695 | C++ | 1269934803/LeetCode | /leetcode232.cpp | UTF-8 | 1,926 | 2.96875 | 3 | [] | no_license | /*************************************************************************
> File Name: leetcode232.cpp
> Author: ma6174
> Mail: ma6174@163.com
> Created Time: 2020年02月27日 星期四 22时18分40秒
************************************************************************/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
using namespace std;
typedef struct MyStack {
int *data;
int top;
}MyStack;
MyStack *MyStackCreate(int size) {
MyStack *s = (MyStack *)malloc(sizeof(MyStack));
s->data = (int *)malloc(sizeof(int) * size);
s->top = -1;
return s;
}
void MyStackPush(MyStack *obj, int x) {
obj->data[++(obj->top)] = x;
}
int MyStackPop(MyStack *obj) {
return obj->data[(obj->top--)];
}
int MyStackTop(MyStack *obj) {
return obj->data[obj->top];
}
int MyStackEmpty(MyStack *obj) {
return obj->top == -1;
}
void MyStackFree(MyStack *obj) {
if (obj == NULL) return ;
free(obj->data);
free(obj);
return ;
}
typedef struct {
MyStack *s1, *s2;
} MyQueue;
MyQueue *myQueueCreate() {
int size = 1024;
MyQueue *q = (MyQueue *)malloc(sizeof(MyQueue));
q->s1 = MyStackCreate(size);
q->s2 = MyStackCreate(size);
return q;
}
void myQueuePush(MyQueue *obj, int x) {
MyStackPush(obj->s1, x);
}
int myQueuePop(MyQueue *obj) {
if (MyStackEmpty(obj->s2)) {
while (!MyStackEmpty(obj->s1)) {
MyStackPush(obj->s2, MyStackPop(obj->s1));
}
}
return MyStackPop(obj->s2);
}
int myQueuePeek(MyQueue *obj) {
if (MyStackEmpty(obj->s2)) {
while (!MyStackEmpty(obj->s1)) {
MyStackPush(obj->s2, MyStackPop(obj->s1));
}
}
return MyStackTop(obj->s2);
}
bool myQueueEmpty(MyQueue *obj) {
return MyStackEmpty(obj->s1) && MyStackEmpty(obj->s2);
}
void myQueueFree(MyQueue *obj) {
if (obj == NULL) return ;
MyStackFree(obj->s1);
MyStackFree(obj->s2);
free(obj);
return ;
}
| true |
4d198e6424082f4b39b5fb762b4a9e6c3cbd2c52 | C++ | ajunlonglive/Hands-On-Design-Patterns-with-Qt-5 | /ch02/IntrospectionExample/Person.cpp | UTF-8 | 1,102 | 2.828125 | 3 | [
"MIT"
] | permissive | #include "Person.h"
#include <QVariant>
Person::Person(QObject *parent)
: QObject(parent),
m_name(),
m_birthday(),
m_heightCm(),
m_gender(UNSPECIFIED)
{
// tell the metaobject system about our type
qRegisterMetaType<Person *>();
}
QString Person::name() const
{
return m_name;
}
void Person::setName(const QString &name)
{
m_name = name;
}
QDate Person::birthday() const
{
return m_birthday;
}
void Person::setBirthday(const QDate &birthday)
{
m_birthday = birthday;
}
int Person::heightCm() const
{
return m_heightCm;
}
void Person::setHeightCm(int heightCm)
{
m_heightCm = heightCm;
}
Person::Genders Person::gender() const
{
return m_gender;
}
void Person::setGender(Person::Genders sex)
{
m_gender = sex;
}
void Person::CloneFrom(const Person &p)
{
m_name = p.m_name;
m_birthday = p.m_birthday;
m_heightCm = p.m_heightCm;
m_gender = p.m_gender;
}
void Person::OutputToXML(QString *output)
{
/// @todo Implement Me!
}
void Person::ReadFromXML(QString input)
{
/// @todo Implement Me!
}
| true |
30ff452e90fa5095769be29d26994eb5bdd6ba23 | C++ | dscvr-com/online-stitcher | /src/test/slerpTest.cpp | UTF-8 | 2,001 | 2.640625 | 3 | [] | no_license | #include <iostream>
#include <algorithm>
#include "../stitcher/simpleSphereStitcher.hpp"
using namespace std;
using namespace cv;
using namespace optonaut;
void CreateRotationPhiTheta(const double phi, const double theta, Mat &res) {
Mat rPhi, rTheta;
CreateRotationY(phi, rPhi);
CreateRotationX(theta, rTheta);
res = rPhi * rTheta;
}
int main(int, char**) {
const bool drawDebug = false;
SimpleSphereStitcher debugger;
Mat start;
Mat end;
// For equality testing, only 1d lerp supported.
// Veryfiy others by drawDebug = true.
double phiStart = M_PI, phiEnd = -M_PI;
double thetaStart = 0, thetaEnd = 0;
CreateRotationPhiTheta(phiStart, thetaStart, start);
CreateRotationPhiTheta(phiEnd, thetaEnd, end);
Mat intrinsics = Mat::eye(3, 3, CV_64F);
intrinsics.at<double>(0, 2) = 2;
intrinsics.at<double>(1, 2) = 2;
Mat canvas = Mat::zeros(2000, 2000, CV_8UC3);
for(double i = 0; i <= 1; i += 0.01) {
Mat slerp = Mat::eye(4, 4, CV_64F);
Mat lerp;
CreateRotationPhiTheta(phiStart * (1 - i) + phiEnd * i,
thetaStart * (1 - i) + thetaEnd * i, lerp);
Slerp(start, end, i, slerp);
Point projectedSlerp = debugger.WarpPoint(intrinsics, slerp,
Size(2, 2), Point(1, 1));
Point projectedLerp = debugger.WarpPoint(intrinsics, lerp,
Size(2, 2), Point(1, 1));
if(drawDebug) {
cv::circle(canvas, projectedLerp, 8,
Scalar(0x00, 0xFF, 0x00), -1);
cv::circle(canvas, projectedSlerp, 8,
Scalar(0x00, 0x00, 0xFF), -1);
if(!drawDebug) {
AssertEQ(projectedSlerp, projectedLerp);
}
}
}
if(drawDebug) {
imwrite("dbg/slerp.png", canvas);
}
cout << "[\u2713] Slerp support module." << endl;
return 0;
}
| true |
6f1e299dc34625b04b26e103b69d77e332f272c9 | C++ | UnforeseenOcean/scenegraphhh | /Node.cpp | UTF-8 | 1,629 | 2.625 | 3 | [] | no_license | //
// Node.cpp
// Node
//
// Created by T.K. Broderick on 10/11/14.
//
//
#include "Node.h"
using namespace ci;
using namespace ci::app;
using namespace std;
void Node::setPosition( const ci::vec3& position ){
mPosition = position;
setMatrix( mat4( translate( position ) ) );
}
void Node::setRotation( const ci::vec3& axis, const float& degree ){
mRotationAxis = axis;
mRotationDegree = degree;
setMatrix( mat4( rotate( degree, axis ) ) );
}
void Node::setScaled( const ci::vec3& scale ){
mScale = scale;
setMatrix( mat4( glm::scale( scale ) ) );
}
void Node::updatePosition( const ci::vec3& position ){
updateMatrix( mat4( translate( position ) ) );
}
void Node::updateRotation( const ci::vec3& axis, const float& degree ){
updateMatrix( mat4( rotate( degree, axis ) ) );
}
void Node::updateScaled( const ci::vec3& scale ){
updateMatrix(mat4( glm::scale( scale ) ));
}
void Node::lookAt( const ci::vec3& position, const ci::vec3& center_of_interest ){
vec3 diff = position - center_of_interest;
mLookDirection = normalize(diff);
mModelMatrix = mat4( translate(position) );
}
void Node::setMatrix(const ci::mat4 &matrix){
mModelMatrix = matrix;
}
void Node::updateMatrix(const ci::mat4 &matrix){
mModelMatrix *= matrix;
}
void Node::draw(){
gl::ScopedModelMatrix push;
if( mParent )
gl::multModelMatrix(mModelMatrix * mParent->mModelMatrix);
else
gl::multModelMatrix(mModelMatrix);
gl::drawColorCube( vec3( 0,0,0 ), vec3( 1,1,1 ) );
auto it = mChildren.begin();
auto end = mChildren.end();
while (it != end) {
it->second->draw();
it++;
}
} | true |
09117f1208ce4d963e5a9e32e6506205adea4172 | C++ | y4my4my4m/ZenithOS | /src/Kernel/BlkDev/DiskDirA.CC | UTF-8 | 4,965 | 2.875 | 3 | [
"Unlicense"
] | permissive | Bool DirNew(CDrive *drive,U8 *cur_dir,CDirEntry *tmpde,Bool free_old_chain=TRUE)
{//Makes a directory entry in the directory from a $LK,"CDirEntry",A="MN:CDirEntry"$ node.
switch (drive->fs_type) {
case FSt_REDSEA:
return RedSeaDirNew(drive,cur_dir,tmpde,free_old_chain);
case FSt_FAT32:
return FAT32DirNew(drive,cur_dir,tmpde,free_old_chain);
default:
PrintErr("File System Not Supported\n");
return FALSE;
}
}
U0 DirEntryDel(CDirEntry *tmpde)
{//Free node returned from $LK,"FilesFind",A="MN:FilesFind"$(). Doesn't Free user_data.
//Does not change the directory on disk.
if (tmpde) {
Free(tmpde->full_name);
Free(tmpde);
}
}
U0 DirEntryDel2(CDirEntry *tmpde)
{//Free node returned from $LK,"FilesFind",A="MN:FilesFind"$(). Frees user_data
//Does not change the directory on disk.
if (tmpde) {
Free(tmpde->full_name);
Free(tmpde->user_data);
Free(tmpde);
}
}
U0 DirTreeDel(CDirEntry *tmpde)
{//Free tree returned from $LK,"FilesFind",A="MN:FilesFind"$(). Doesn't Free user_data.
//Does not change the directory on disk.
CDirEntry *tmpde2;
while (tmpde) {
tmpde2=tmpde->next;
if (tmpde->sub)
DirTreeDel(tmpde->sub);
DirEntryDel(tmpde);
tmpde=tmpde2;
}
}
U0 DirTreeDel2(CDirEntry *tmpde)
{//Free tree returned from $LK,"FilesFind",A="MN:FilesFind"$(). Frees user_data
//Does not change the directory on disk.
CDirEntry *tmpde2;
while (tmpde) {
tmpde2=tmpde->next;
if (tmpde->sub)
DirTreeDel2(tmpde->sub);
DirEntryDel2(tmpde);
tmpde=tmpde2;
}
}
I64 DirEntryCompareName(CDirEntry *e1,CDirEntry *e2)
{
U8 buf1[CDIR_FILENAME_LEN],buf2[CDIR_FILENAME_LEN],
buf3[CDIR_FILENAME_LEN],buf4[CDIR_FILENAME_LEN];
I64 d1=0,d2=0;
if (e1->attr & RS_ATTR_DIR)
d1=1;
if (e2->attr & RS_ATTR_DIR)
d2=1;
if (d1!=d2)
return d2-d1;
else {
StrCopy(buf1,e1->name);
StrCopy(buf2,e2->name);
FileExtRemove(buf1,buf3);
FileExtRemove(buf2,buf4);
if (d1=StrCompare(buf3,buf4))
return d1;
return StrCompare(buf1,buf2);
}
}
I64 DirEntryCompareClus(CDirEntry *e1,CDirEntry *e2)
{
return e1->clus-e2->clus;
}
#define SK_NAME 0
#define SK_CLUS 1
U0 DirFilesSort(CDirEntry **_tmpde,I64 key)
{
I64 i,count;
CDirEntry *tmpde=*_tmpde,*tmpde1,**sort_buf;
if (tmpde) {
count=LinkedListCount(tmpde);
if (count>1) {
sort_buf=MAlloc(count*sizeof(U8 *));
i=0;
tmpde1=tmpde;
while (tmpde1) {
sort_buf[i++]=tmpde1;
tmpde1=tmpde1->next;
}
switch [key] {
case SK_NAME:
QuickSortI64(sort_buf,count,&DirEntryCompareName);
break;
case SK_CLUS:
QuickSortI64(sort_buf,count,&DirEntryCompareClus);
break;
}
tmpde=sort_buf[0];
*_tmpde=tmpde;
for (i=0;i<count-1;i++) {
tmpde1=sort_buf[i];
tmpde1->next=sort_buf[i+1];
}
tmpde1=sort_buf[i];
tmpde1->next=NULL;
Free(sort_buf);
tmpde1=tmpde;
while (tmpde1) {
if (tmpde1->sub)
DirFilesSort(&tmpde1->sub,key);
tmpde1=tmpde1->next;
}
} else
if (tmpde->sub)
DirFilesSort(&tmpde->sub,key);
}
}
CDirEntry *DirFilesFlatten(CDirEntry *tmpde,CDirEntry **_res,I64 fuf_flags)
{//Returns last node
CDirEntry *tmpde1;
Bool del;
if (tmpde)
while (TRUE) {
tmpde1=tmpde->next;
if (!(tmpde->attr&RS_ATTR_DIR)||!(fuf_flags&FUF_JUST_FILES)) {
_res=*_res=tmpde;
del=FALSE;
} else
del=TRUE;
if (tmpde->sub) {
_res=DirFilesFlatten(tmpde->sub,_res,fuf_flags);
tmpde->sub=NULL;
}
if (del)
DirEntryDel(tmpde);
if (tmpde1)
tmpde=tmpde1;
else
break;
}
*_res=NULL;
return _res;
}
U0 PutFileLink(U8 *filename,U8 *full_name=NULL,I64 line=0,Bool plain_text=FALSE)
{//Put $LK,"DolDoc",A="FI:::/Doc/DolDocOverview.DD"$ file,line link to StdOut, $LK,"DocPut",A="MN:DocPut"$.
U8 *st;
if (!filename) return;
if (IsRaw) {
if (line)
"%s,%04d",filename,line;
else
"%s",filename;
} else {
//LK_DOC,LK_DOC_ANCHOR,LK_DOC_FIND,LK_DOC_LINE
if (filename[0]=='A'&&filename[2]==':') {
if (line) //See $LK,"SpriteEdText",A="MN:SpriteEdText"$()
"$$LK,\"%s,%04d\",A=\"AL:%s,%d\"$$",filename+3,line,filename+3,line;
else
"$$LK,\"%s\",A=\"AI:%s\"$$",filename+3,filename+3;
} else {
if (!full_name)
full_name=st=FileNameAbs(filename);
else
st=NULL;
if (plain_text) {
if (line)
"$$LK,\"%s,%04d\",A=\"PL:%s,%d\"$$",filename,line,full_name,line;
else
"$$LK,\"%s\",A=\"PI:%s\"$$",filename,full_name;
} else {
if (line)
"$$LK,\"%s,%04d\",A=\"FL:%s,%d\"$$",filename,line,full_name,line;
else
"$$LK,\"%s\",A=\"FI:%s\"$$",filename,full_name;
}
Free(st);
}
}
}
U0 PutDirLink(U8 *dirname,U8 *full_name=NULL)
{//Put $LK,"DolDoc",A="FI:::/Doc/DolDocOverview.DD"$ dir macro to StdOut, $LK,"DocPut",A="MN:DocPut"$.
U8 *st;
if (!dirname) return;
if (IsRaw)
"%s",dirname;
else {
if (!full_name)
full_name=st=DirNameAbs(dirname);
else
st=NULL;
"$$MA,T=\"%s\",LM=\"Cd(\\\"%s\\\");Dir;\n\"$$",dirname,full_name;
Free(st);
}
}
| true |
6fe8d9a4937a782152a9cbf5a393c3c20ea085af | C++ | seaslee/rome | /matrix/matrix.h | UTF-8 | 13,308 | 3.046875 | 3 | [] | no_license | /**
* A template class to implement matrix and support element-wise operation on it
*
* This class implements the template matrix. Matrix object can be constructed
* by the following ways:
*
* a. a matrix can be constructed with the matrix_initializer_list (
* a.k, recursive initializer_list). The memory of matrix is controlled by a default
* memory object.
*
* For example:
* Matrix<float, 2> amat {{1,2}, {2, 4}};
*
* b. the matrix can also constructed with a memory allocator and the shape of matrix.
*
* For example:
* storage::Allocator * a = new storage::CPUallocator;
* Matrix<float 2> rmat(a, {2,2});
* Note that the memory is uninitialized.
*
* c. the matrix can also be gotten from copy constructor and copy assignment. The new
* matrix is shared the memory with the origin matrix.
*
*/
#ifndef MATRIX_H_
#define MATRIX_H_
#include <iostream>
#include <fstream>
#include <cblas.h>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <memory>
#include <initializer_list>
#include <type_traits>
#include <array>
#include "expr.h"
#include "matrix_shape.h"
#include "../storage/buffer.h"
//#define DEBUG
namespace snoopy {
namespace matrix {
// recursive initializer_list for Matrix Class
template<typename DataType, size_t N>
struct MatrixInit {
using type = std::initializer_list<typename MatrixInit<DataType, N-1>::type>;
};
template<typename DataType>
struct MatrixInit<DataType, 1> {
using type = std::initializer_list<DataType>;
};
template<typename DataType>
struct MatrixInit<DataType, 0>;
template<typename DataType, size_t N>
using matrix_initializer_list = typename MatrixInit<DataType, N>::type;
template<typename DataType, size_t N>
class Matrix : public ExprBase<Matrix<DataType, N>, DataType> {
public:
/** default constructor
*/
Matrix()
: data(nullptr),
stride(size_t(0)),
capicity(size_t(0)),
row(size_t(0)),
column(size_t(0)) {
}
;
/**
* constructor with a memory allocator and matrix shape
*
* @param a: allocate the memory
* @param s: shape of matrix
*/
Matrix(storage::Allocator * a, const MatrixShape<N> &s);
/**
* constructor with matrix shape
*
* @param a: allocate the memory
* @param s: shape of matrix
*/
Matrix(const MatrixShape<N> &s);
/**
* constructor with a memory allocator, matrix shape and stride
*
* @param a: buffer storage
* @param s: shape of the matrix
* @param st: stride for each row of the multi-array
* Note that align memory and change the shape[N-1] memeory
*/
Matrix(storage::TensorBuffer<DataType> * a, const MatrixShape<N> &s, const size_t st);
/**
* constructor with a memory allocator, matrix shape and stride
*
* @param a: allocate the memory
* @param s: shape of the matrix
* @param st: stride for each row of the multi-array
* Note that align memory and change the shape[N-1] memeory
*/
Matrix(storage::Allocator * a, const MatrixShape<N> &s, const size_t st);
/**
* copy constructor
*
* @param m: another matrix to be cloned to this matrix
*
* @return the matrix that has copied data from another matrix
*/
Matrix(const Matrix<DataType, N> &m);
/**
* copy assignment
*
* @param m: another matrix to be cloned to this matrix
*
* @return the matrix that has copied data from another matrix
*/
Matrix<DataType, N> & operator =(const Matrix<DataType, N> &m);
/**
* move copy constructor
*
* @param m: another matrix to be cloned to this matrix
*
* @return the matrix that has copied data from another matrix
*/
Matrix(Matrix<DataType, N> &&m);
/**
* move assignment operator
*
* @param m: matrix to be moved to this matrix
*
* @return the matrix that has gotten data from another matrix
*
*/
Matrix<DataType, N> & operator =(Matrix<DataType, N> &&m);
/**
* constructor with matrix_initializer_list
*
* @param t is initializer_list for the matrix
*/
Matrix(matrix_initializer_list<DataType, N> t);
/**
* assignment operator with matrix_initializer_list
*
* @param t is initializer_list for the matrix
*
* @return the matrix that has filled the data with the initializer_list
*/
Matrix & operator =(matrix_initializer_list<DataType, N> t);
template<typename T>
Matrix(std::initializer_list<T> t) = delete;
template<typename T>
Matrix & operator =(std::initializer_list<T> t) = delete;
/**
* de-constructor
*/
~Matrix() {
if (data) {
data->unref();
}
}
/**
* index operation for the matrix
*
* @param i is the index
*
* @return a Matrix Object which is refer to some elements in the Matrix Object
*/
inline Matrix<DataType, N - 1> operator[](size_t i) const;
inline Matrix<DataType, N - 1> operator[](size_t i);
/**
* slice function for the matrix
*
* @param i is the start index
* @param j is the end index
*
* @return a SubMatrix Object which is refer to some elements in the Matrix Object
*/
inline Matrix<DataType, N> slice(size_t i, size_t j) const;
inline Matrix<DataType, N> slice(size_t i, size_t j);
/**
* Scalar add Operator
*
* @param n is the scalar added to matrix
*
* @return the matrix in which the elements are all added the scalar value
*/
inline Matrix<DataType, N> & operator +=(const DataType & n);
/**
* Scalar sub Operator
*
* @param n is the scalar subscribed to matrix
*
* @return the matrix in which the elements are all subscribed the scalar value
*/
inline Matrix<DataType, N> & operator -=(const DataType & n);
/**
* Scalar multiply Operator
*
* @param n is the scalar multiplied to matrix
*
* @return the matrix in which the elements are all multiplied the scalar value
*/
inline Matrix<DataType, N> & operator *=(const DataType & n);
/**
* Scalar devision Operator
*
* @param n is the scalar divided to matrix
*
* @return the matrix in which the elements are all devided the scalar value
*/
inline Matrix<DataType, N> & operator /=(const DataType & n);
/**
* add Operator
*
* @param t is the matrix added to this matrix
*
* @return the matrix in which the elements: m1(i,j) += m2(i,j)
*/
inline Matrix<DataType, N> & operator +=(const Matrix<DataType, N> & t);
/**
* sub Operator
*
* @param t is the matrix subscribed to this matrix
*
* @return the matrix in which the elements: m1(i,j) -= m2(i,j)
*/
inline Matrix<DataType, N> & operator -=(const Matrix<DataType, N> & t);
/**
* multiply Operator
*
* @param t is the matrix multiplied to this matrix
*
* @return the matrix in which the elements: m1(i,j) *= m2(i,j)
*/
inline Matrix<DataType, N> & operator *=(const Matrix<DataType, N> & t);
/**
* division opertor
*
* @param t is the matrix divided to this matrix
*
* @return the matrix in which the elements: m1(i,j) /= m2(i,j)
*/
inline Matrix<DataType, N>& operator /=(const Matrix<DataType, N> & t);
/**
* assign Operator
*
* @param e is the right matrix object or a scalar
*
* @return the result matrix
*/
template<typename SubType>
inline Matrix<DataType, N>& operator=(const ExprBase<SubType, DataType> &e);
/**
* get the basic element in index (i,j)
*
* @param i is the row index
* @param j is the column index
*
* @return the element in the index(i,j)
*/
inline DataType eval(size_t i, size_t j) const;
inline void set_row_ele(int i, const Matrix<DataType, N> & s);
inline size_t get_column() const {
return column;
}
inline size_t get_row() const {
return row;
}
inline int get_capicity() const;
inline int get_size() const;
/**
* get the length of the shape
* @param s is the shape object
* @param stride is the row length
* @return the length of the shape with the stride
*/
inline size_t get_length(const MatrixShape<N> &s, size_t stride) const;
inline storage::TensorBuffer<DataType> * get_data() {
return data;
}
inline storage::TensorBuffer<DataType> * get_data() const {
return data;
}
inline MatrixShape<N> get_shape() const { return shape; }
inline size_t get_stride() const {return stride;}
inline size_t get_stride() {return stride;}
inline void set_shape(const MatrixShape<N> & s) { shape = s; }
inline void set_stride(const size_t s) { stride = s; }
inline void set_capicity(const size_t c) { capicity = c;}
inline void set_data(storage::TensorBuffer<DataType> * d) { data = d; }
inline void set_row(const size_t r) {row = r;}
inline void set_column(const size_t c) { column = c; }
inline void get_size() {return row * column;};
/*
* copy data from source matrix to this matrix
* make sure the capicity larger than the source matrix
*
* param s: source target
*/
inline void copy_from(const Matrix<DataType, N> & s);
/**
* set data field to zero
*/
inline void clear_data();
private:
MatrixShape<N> shape;
size_t stride;
size_t capicity;
storage::TensorBuffer<DataType> * data;
size_t row;
size_t column;
};
/**
* The matrix for the specified one dimension matrix(vector)
*
*/
template<typename DataType>
class Matrix<DataType, 1> : public ExprBase<Matrix<DataType, 1>, DataType> {
public:
Matrix()
: data(nullptr),
stride(size_t(0)) {
}
;
Matrix(storage::Allocator * a, const MatrixShape<1> &s);
Matrix(storage::Allocator * a, const MatrixShape<1> &s, const size_t st);
Matrix(const MatrixShape<1> &s);
Matrix(const MatrixShape<1> &s, const size_t st);
Matrix(const Matrix<DataType, 1> &m);
Matrix<DataType, 1> & operator =(const Matrix<DataType, 1> &m);
Matrix(Matrix<DataType, 1> &&m);
Matrix<DataType, 1> & operator =(Matrix<DataType, 1> &&m);
Matrix(matrix_initializer_list<DataType, 1> t);
Matrix & operator =(matrix_initializer_list<DataType, 1> t);
~Matrix() {
if (data) {
data->unref();
}
}
int get_capicity() const;
int get_size() const;
size_t get_length(const MatrixShape<1> &s, size_t stride) const;
storage::TensorBuffer<DataType> * get_data() {
return data;
}
storage::TensorBuffer<DataType> * get_data() const {
return data;
}
const DataType & operator[](size_t i) const;
DataType & operator[](size_t i);
Matrix<DataType, 1> slice(size_t i, size_t j) const;
Matrix<DataType, 1> slice(size_t i, size_t j);
Matrix<DataType, 1> & operator +=(const DataType & n);
Matrix<DataType, 1> & operator -=(const DataType & n);
Matrix<DataType, 1> & operator *=(const DataType & n);
Matrix<DataType, 1> & operator /=(const DataType & n);
Matrix<DataType, 1> & operator +=(const Matrix<DataType, 1> & t);
Matrix<DataType, 1> & operator -=(const Matrix<DataType, 1> & t);
Matrix<DataType, 1> & operator *=(const Matrix<DataType, 1> & t);
Matrix<DataType, 1>& operator /=(const Matrix<DataType, 1> & t);
template<typename SubType>
Matrix<DataType, 1>& operator=(const ExprBase<SubType, DataType> &e);
DataType eval(size_t i, size_t j) const;
void set_row_ele(int i, const Matrix<DataType, 1> & s);
size_t get_column() const {
return column;
}
size_t get_row() const {
return row;
}
inline size_t get_stride() const {return stride;}
inline size_t get_stride() {return stride;}
inline MatrixShape<1> get_shape() const {return shape;}
inline void set_shape(const MatrixShape<1> & s) { shape = s; }
inline void set_stride(const size_t s) { stride = s; }
inline void set_capicity(const size_t c) { capicity = c;}
inline void set_data(storage::TensorBuffer<DataType> * d) { data = d; }
inline void set_row(const size_t r) {row = r;}
inline void set_column(const size_t c) { column = c; }
inline void copy_from(const Matrix<DataType, 1> & s);
inline void clear_data();
private:
MatrixShape<1> shape;
size_t stride;
size_t capicity;
storage::TensorBuffer<DataType> * data;
size_t row;
size_t column;
};
template<typename DataType>
inline bool float_equal(const DataType& f1, const DataType& f2) {
if (std::fabs(f1-f2) <= 1e-6) {
return true;
}
return false;
}
/**
* Ruturn true if all elements in the matrix is equal and stride is equal
*
*/
template<typename DataType, size_t N>
inline bool operator==(const Matrix<DataType, N>& m1,
const Matrix<DataType, N>& m2) {
storage::TensorBuffer<DataType> * d1 = m1.get_data();
storage::TensorBuffer<DataType> * d2 = m2.get_data();
if (m1.get_size() != m2.get_size())
return false;
for (size_t i = 0; i < m1.get_size(); ++i) {
if (!float_equal(d1->at(i), d2->at(i)))
return false;
}
return true;
}
} //namespace matrix
} //namespace snoopy
#ifdef MATRIX_SCALAR_TYPE_
#error "MATRIX_SCALAR_TYPE_ Should not be defined!"
#endif
#define MATRIX_SCALAR_TYPE_ float
#include "expr-inl.h"
#undef MATRIX_SCALAR_TYPE_
#define MATRIX_SCALAR_TYPE_ double
#include "expr-inl.h"
#undef MATRIX_SCALAR_TYPE_
#define MATRIX_SCALAR_TYPE_ int
#include "expr-inl.h"
#undef MATRIX_SCALAR_TYPE_
#include "matrix-inl.h"
#include "matrix_math.h"
#include "random.h"
#endif // MATRIX_MATRIX_H
| true |
feb8877c630942c3a7386c31009f40ce471113d8 | C++ | Frozen-Team/3FEngine | /src/utils/f_file_loader.cxx | UTF-8 | 632 | 2.703125 | 3 | [
"MIT"
] | permissive | #include "f_file_loader.hpp"
#include <fstream>
#include <fcomponents/f_logger.hpp>
namespace fengine
{
namespace futils
{
FFileLoader::FFileLoader(const FString & file_path)
{
LoadFile(file_path);
}
void FFileLoader::LoadFile(const FString& file_path)
{
std::ifstream in_file;
in_file.open(file_path.c_str());
if (in_file.is_open())
{
data.assign(std::istreambuf_iterator<char>(in_file), std::istreambuf_iterator<char>());
}
else
{
data.clear();
LOG(WARNING) << "Cannot load file: " << file_path;
}
}
const FString& FFileLoader::ToString()
{
return data;
}
}
}
| true |
c635e97f1495fa8940ff1133658e085489ad05dc | C++ | ZzEeKkAa/eolimp | /1948.cpp | UTF-8 | 1,188 | 2.609375 | 3 | [] | no_license | #include <iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
vector<vector<int> > g;
vector<int> used;
vector<int> inDegree;
vector<int> top;
queue<int> q;
int main(){
ifstream fin("input.txt");
ofstream fout("output.txt");
int n,m,a,b;
int from,to;
vector<int>::iterator finish;
fin>>n>>m;
inDegree.assign(n+1,0);
used.assign(n+1,0);
g.assign(n+1, vector<int>());
for(int i=0; i<m; ++i){
fin>>a>>b;
g[a].push_back(b);
++inDegree[b];
}
for(int i=1; i<=n; i++){
if(inDegree[i]==0) q.push(i);
}
while(!q.empty()){
from=q.front();
finish = g[from].end();
for(vector<int>::iterator it = g[from].begin(); it<finish; it++){
to = *it;
--inDegree[to];
if(inDegree[to]==0) q.push(to);
}
top.push_back(from);
q.pop();
}
if(top.size()!=n) {top.clear(); top.push_back(-1);}
vector<int>::iterator it = top.begin();
finish = top.end();
fout<<*it; it++;
for(; it<finish; it++){
fout<<" "<<*it;
}
fout<<endl;
fin.close();
fout.close();
}
| true |
64c94051574b2eef56fc9d3a5ad71f108c8e0ce2 | C++ | anukiii/GameSims | /CSC8503/CSC8503Common/StateTransition.h | UTF-8 | 836 | 2.8125 | 3 | [] | no_license | #pragma once
#include <functional >
namespace NCL {
namespace CSC8503 {
class State;
typedef std::function <bool()> StateTransitionFunction;
class StateTransition {
public:
StateTransition(State* source , State* dest ,
StateTransitionFunction f) {
sourceState = source;
destinationState = dest;
function = f;
}
bool CanTransition () const {return function ();}
State* GetDestinationState () const {return destinationState ;}
State* GetSourceState () const {return sourceState; }
protected:
State * sourceState;
State * destinationState;
StateTransitionFunction function;
};
}
} | true |
5a463670e97c81e549964d0292cee089ebfa2348 | C++ | kannavue/ChartPatternRecognitionLib | /src/math/UnsignedIntRange.h | UTF-8 | 560 | 2.6875 | 3 | [
"MIT"
] | permissive | /*
* UnsignedIntRange.h
*
* Created on: Jul 31, 2014
* Author: sroehling
*/
#ifndef UNSIGNEDINTRANGE_H_
#define UNSIGNEDINTRANGE_H_
class UnsignedIntRange {
private:
unsigned int minVal_;
unsigned int maxVal_;
public:
UnsignedIntRange(unsigned int minVal, unsigned int maxVal);
bool valueWithinRange(unsigned int val) const { return (val >= minVal_) && (val <= maxVal_); }
unsigned int maxVal() const { return maxVal_; }
unsigned int minVal() const { return minVal_; }
virtual ~UnsignedIntRange() {}
};
#endif /* UNSIGNEDINTRANGE_H_ */
| true |
82ff3fc948b63003f3446b497f8e7f07b73f70cf | C++ | Nils2332/Timelapsebuild | /Software/Remote-Control/Drivers/Joystick/joycon.cpp | UTF-8 | 1,583 | 2.53125 | 3 | [
"MIT"
] | permissive | /*
* joycon.cpp
*
* Created on: 22.02.2019
* Author: Nils
*/
#include "joycon.h"
#include "math.h"
#include "gpio.h"
#include "adc.h"
int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
joycon::joycon(ADC_HandleTypeDef* hadc, uint32_t Channel0, uint32_t Channel1,
GPIO_TypeDef* GPIOx, uint32_t Button)
{
this->hadc = hadc;
this->Channel0 = Channel0;
this->Channel1 = Channel1;
}
void joycon::init()
{
getjoycon();
joyval_offset[0] = joyval[0];
joyval_offset[1] = joyval[1];
}
void joycon::update()
{
getjoycon();
for(uint8_t i=0; i<2; i++)
{
joyval[i] = (joyval[i]-joyval_offset[i])/-10;
if(abs(joyval[i])<8) joyval[i] = 0;
if(joyval[i]>150) joyval[i] = 150;
if(joyval[i]<-150) joyval[i] = -150;
joyval[i] /=150;
// if(joyval[i] > 0 ) joyval[i]= sqrt(joyval[i]);
// if(joyval[i] < 0 ) joyval[i]= -sqrt(-joyval[i]);
}
}
void joycon::getjoycon()
{
ADC_ChannelConfTypeDef sConfig = {0};
sConfig.Channel = Channel0;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
HAL_ADC_ConfigChannel(hadc, &sConfig);
getvals(0);
sConfig.Channel = Channel1;
HAL_ADC_ConfigChannel(hadc, &sConfig);
getvals(1);
}
void joycon::getvals(uint8_t axis)
{
joyval[axis] = 0;
for(uint8_t j=0; j<mean; j++)
{
for(uint8_t i = 0; i < mid; i++) {
HAL_ADC_Start(hadc);
HAL_ADC_PollForConversion(hadc, 1);
adc_buf[i] = HAL_ADC_GetValue(hadc);
HAL_ADC_Stop(hadc);
}
qsort(adc_buf, mid, sizeof(uint16_t), compare);
joyval[axis] += adc_buf[midpos];
}
joyval[axis] = (joyval[axis]/mean);
}
| true |
bec658e825e4e1274e9c93dedb63bd0a52aa59be | C++ | mjiricka/gongfu-tea-timer | /helpers/printer/main.cpp | UTF-8 | 820 | 3.09375 | 3 | [
"MIT"
] | permissive | #include <iostream>
#include <thread>
#include <chrono>
#include <Printer.h>
using std::cout;
using std::endl;
using std::this_thread::sleep_for;
using std::chrono::milliseconds;
int main() {
Printer printer(true);
const milliseconds sleepTime{100};
const int total = 76;
printer.drawPausedProgressBar(80, .25, 20, total);
printer.drawCancelledProgressBar(80, .5, 20, total);
cout << endl;
for (int i = 1; i <= total; ++i) {
if (i != 1) printer.eraseOutput(1);
double fraction = static_cast<double>(i) / total;
printer.drawProgressBar(80, fraction, i, total);
printer.drawNotice(" [p - pause, c - cancel]> ");
if (i < total) {
sleep_for(sleepTime);
}
}
cout << endl;
printer.eraseOutput(1);
return 0;
}
| true |
56d75b786fd6445298cb4065e357f55616f4b6b0 | C++ | muhammedozkan/CSE241-Object-Oriented-Programming | /HW6/Iterator.h | UTF-8 | 859 | 2.984375 | 3 | [] | no_license | //============================================================================
// Name : Iterator.h
// Author : MuhammedOZKAN 151044084
// Version :
// Copyright : @pithblood
// Description :
//============================================================================
#include <iostream>
#ifndef ITERATOR_H_
#define ITERATOR_H_
using namespace std;
namespace GTU
{
template <typename T>
class Iterator
{
//public members
public:
Iterator();
Iterator(const Iterator &);
~Iterator();
T &next() const; //Returns true if the iteration has more elements.
bool hasNext(); //Returns the next element in the iteration and advances the iterator.
void remove(); //Removes from the underlying collection the last element returned by this iterator
//private members
private:
T *itr;
};
} // namespace GTU
#endif /* ITERATOR_H_ */ | true |
589ae5caca6f1fe2360fcc428afc3834a7024bd1 | C++ | MicuEmerson/AlgorithmicProblems | /campion.edu/MutariCAL/main.cpp | UTF-8 | 1,089 | 2.53125 | 3 | [] | no_license | #include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
ifstream fin("saritura_calului1.in");
ofstream fout("saritura_calului1.out");
int i,j,d,l_next,c_next;
int dl[8]= {-2,2,1,2,2,1,-1,-2};
int dc[8]= {1,-1,2,1,-1,-2,-2,-1};
int a[101][101];
int n,m,k=0,li,ci;
void mutariCal(int a[101][101],int n,int m, int li,int ci, int k)
{
if(k==n*n)
{
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
else
{
for(d=0; d<=7; d++)
{
l_next=li+dl[d];
c_next=ci+dc[d];
if(l_next>=1 && l_next<=n && c_next>=1 && c_next<=m)
{
if(a[l_next][c_next]==0)
{
a[l_next][c_next]=k+1;
mutariCal(a,n,m,l_next,c_next,k+1);
a[l_next][c_next]=0;
}
}
}
}
}
int main()
{
cin>>n>>m>>li>>ci;
mutariCal(a,n,n,li,ci,k);
return 0;
}
| true |
f58199f1a74023b1931c7225f1655c2d88a3fe92 | C++ | Pentagon03/competitive-programming | /project-euler/volume06/296.cc | UTF-8 | 1,011 | 2.96875 | 3 | [] | no_license | #include <bits/stdc++.h>
long dfs(long a, long b, long c, long d, int n) {
long x = a + c, y = b + d, xy = x + y;
if (xy * 5 > n) return 0;
long ret = 0;
for (long t = 3; ; ++t) {
int l = (t * y - 1) / xy, r = std::min(t - 1, n / xy - t);
if (r >= l) ret += r - l;
else break;
}
return ret + dfs(a, b, x, y, n) + dfs(x, y, c, d, n);
}
//BE = ac / (a+b)
int naive(int n) {
long ret = 0;
for (int a = 1; a <= n / 3; ++a) {
for (int b = a; b <= (n - a) / 2; ++b) {
int v = std::min(a + b, n - a - b + 1);
int g = std::__gcd(a, a + b);
int z = (a + b) / g;
int r = v / z, l = (b + z - 1) / z;
if (v % z == 0) --r;
if (r >= l) ret += r - l + 1;
}
}
return ret;
}
long run(int n) {
long ret = 0;
for (int a = 2; ; ++a) {
int l = (a - 1) / 2, r = std::min(n / 2 - a, a - 1);
if (r >= l) ret += r - l;
else break;
}
return dfs(0, 1, 1, 1, n) + ret;
}
int main() {
std::cout << run(100000) << std::endl;
return 0;
}
| true |
f6969fe68a5efc06f70a42088df4098072396c90 | C++ | fpusderkis/TP-Final-Taller-I | /Common/ProtocolTranslator/DataDTO/ChellDTO.h | UTF-8 | 1,278 | 2.515625 | 3 | [] | no_license | #ifndef PORTAL_CHELLDTO_H
#define PORTAL_CHELLDTO_H
#include <Common/ProtocolTranslator/ProtocolDTO.h>
class ChellDTO: public ProtocolDTO {
private:
const int16_t _id;
const int16_t _x;
const int16_t _y;
const int16_t _width;
const int16_t _height;
const int16_t _direction;
const int16_t _tilted;
const int16_t _moving;
const int16_t _jumping;
const int16_t _shooting;
const int16_t _delete_state;
public:
ChellDTO(const int16_t& id, const int16_t& x, const int16_t& y, const int16_t& width,
const int16_t& height, const int16_t& direction, const int16_t& tilted,
const int16_t& moving, const int16_t& jumping, const int16_t& shoting,
const int16_t& delete_state);
~ChellDTO() override = default;
int16_t getClassId() const override;
const int16_t getId() const;
const int16_t getX() const;
const int16_t getY() const;
const int16_t getDirection() const;
const int16_t getTilted() const;
const int16_t getJumping() const;
const int16_t getShooting() const;
const int16_t getDeleteState() const;
const int16_t getMoving() const;
const int16_t getWidth() const;
const int16_t getHeight() const;
};
#endif //PORTAL_CHELLDTO_H
| true |
fac636c4473fc6f800dea4f1f5f4211376dff368 | C++ | Yertugan/acm | /stack_queue/regular.cpp | UTF-8 | 287 | 2.90625 | 3 | [] | no_license | #include <iostream>
#include <vector>
using namespace std;
int main(){
string s;
cin >> s;
vector<char> br;
int cnt = 0;
for(int i = 0; i<s.length(); i++){
if(s[i] == '('){
br.push_back(s[i]);
}else if(!br.empty()){
cnt++;
br.pop_back();
}
}
cout << 2*cnt;
}
| true |
5f9822c1b8f3cb7189ad77e9f39c952b0965563e | C++ | alexander-jones/NCV | /core/reporting/networkupdatemanager.h | UTF-8 | 2,498 | 2.71875 | 3 | [] | no_license | #ifndef NETWORKUPDATEMANAGER_H
#define NETWORKUPDATEMANAGER_H
#include <QObject>
#include <QThread>
#include <QTimer>
#include "qreportclient.h"
#include "core/ncsneuronset.h"
#include "core/ncsconnectionset.h"
/*!
\class NetworkUpdateManager
\author Justin Cardoza
\editor
\brief This class manages network updates in one easy interface. Give it a data source and
an update interval, and it will handle retrieving simulation data in a threaded manner.
*/
class NetworkUpdateManager : public QObject
{
Q_OBJECT
public:
explicit NetworkUpdateManager(QObject *parent = 0);
~NetworkUpdateManager();
signals:
///Emitted when the update interval changes.
void updateIntervalChanged(int msec);
///Emitted when updates are started.
void updatesStarted();
///Emitted when updates are stopped.
void updatesStopped();
public slots:
///Establishes a connection to a simulation using a network socket.
///Takes a network host name and port to connect to.
bool connectToHost(const std::string& host, int port);
///Closes a previously opened connection to a simulator.
void disconnectFromHost();
///Sets the neuron set used for storing neuron data, replacing whatever neuron set was used previously.
void setNeurons(NCSNeuronSet *neurons);
///Sets the connection set used for storing connection data, replacing whatever connection set was used previously.
void setConnections(NCSConnectionSet *connections);
///Sets the update interval in milliseconds.
void setUpdateInterval(int msec);
///Starts the update timer.
void startUpdates();
///Stops the update timer.
void stopUpdates();
private slots:
///Updates a specific attribute by pulling data from the report client.
void m_updateAttribute(NCSAttribute *attribute);
///Updates all reportable attributes that are currently active.
void m_updateAttributes();
private:
struct ReportedAttribute
{
std::string name;
QReportClient::Report *report;
NCSAttribute *attribute;
};
void m_addAttribute(const QString& name, NCSAttribute *attribute, int elementCount);
QReportClient m_client;
NCSNeuronSet *m_neurons;
NCSConnectionSet *m_connections;
QMap<NCSAttribute*, ReportedAttribute> m_reported;
unsigned int m_step;
QTimer * m_timer;
};
#endif // NETWORKUPDATEMANAGER_H
| true |
bfdb992b7efe817f0176d2468135a52f866e60dc | C++ | zhoulike/algorithms | /leetcode/longest-common-prefix.cpp | UTF-8 | 681 | 3.046875 | 3 | [] | no_license | class Solution {
public:
string longestCommonPrefix(vector<string> &strs) {
if(strs.size() == 0)
return string("");
int shortest = strs[0].size();
for(int i = 1; i < strs.size(); ++i)
if(strs[i].size() < shortest)
shortest = strs[i].size();
string prefix;
for(int j = 0; j < shortest; ++j) {
prefix.push_back(strs[0][j]);
for(int i = 1; i < strs.size(); ++i) {
if(strs[i][j] != prefix[j]) {
prefix.pop_back();
break;
}
}
}
return prefix;
}
}; | true |
569c7e0c9b5a7583c8e092433c1f026efd038542 | C++ | bughamal/C- | /Cards - 副本/AAAARule.cpp | GB18030 | 4,150 | 2.703125 | 3 | [] | no_license | #include "AAAARule.h"
IMPLEMENT_DYNCREATE(CAAAARule,CRule)
CAAAARule::CAAAARule(void)
{
}
CAAAARule::~CAAAARule(void)
{
}
// ƵĹ
bool CAAAARule::IsGetCardsRule(CCardsRank* pCardsRank, int nlstID, list<Node*>::iterator iteCursorPos)
{
int num = (*iteCursorPos)->pCards->m_nCardsNum;
// ж Dz
while(iteCursorPos != pCardsRank->m_vecRank[nlstID].end())
{
if((*iteCursorPos)->pCards->m_nCardsNum != num) //
return false;
++iteCursorPos;
--num;
}
return true;
}
//
bool CAAAARule::IsOpenCards(POINT point, CCardsRank* pCardsRank)
{
// һǷж
if(pCardsRank->m_vecRank[10].empty() == false)
{
// ж Ƿһ
if(point.x >= pCardsRank->m_vecRank[10].back()->x && point.x <= pCardsRank->m_vecRank[10].back()->x+71
&& point.y >= pCardsRank->m_vecRank[10].back()->y && point.y <= pCardsRank->m_vecRank[10].back()->y+96)
{
// ж ǰ10Ƿп
for(int i=0;i<10;i++)
{
if(pCardsRank->m_vecRank[i].empty() == true)
return false;
}
return true;
}
}
return false;
}
void CAAAARule::OpenCards(CCardsRank* pCardsRank)
{
// һ β 10 ֱŵÿһβ
for(int i=0;i<10;i++)
{
//
pCardsRank->m_vecRank[10].back()->bFlag = true;
pCardsRank->m_vecRank[10].back()->x = pCardsRank->m_vecRank[i].back()->x;
pCardsRank->m_vecRank[10].back()->y = pCardsRank->m_vecRank[i].back()->y+20;
// ڵ ӵ pCardsRank->m_vecRank[i] β
pCardsRank->m_vecRank[i].push_back(pCardsRank->m_vecRank[10].back());
pCardsRank->m_vecRank[10].pop_back();
//
this->DeleteLine(pCardsRank,i);
}
}
// ƵĹ
bool CAAAARule::IsReceiveCardsRule(POINT point, int nlstID, CCardsRank* pCardsRank, list<Node*>& lstCursorCards)
{
// ǰ10Խ
if(nlstID >= 0 && nlstID <= 9)
{
// ǿ
if(pCardsRank->m_vecRank[nlstID].empty() == true)
{
// ж Ƿһ ̶ľοķΧ
if(point.x >= 10+81*nlstID && point.x <= 10+81*nlstID+71
&& point.y >= 10 && point.y <= 10+96)
{
return true;
}
}
else
{
// ǿ ж Dz nlstID ΪڵķΧ
if(point.x >= pCardsRank->m_vecRank[nlstID].back()->x && point.x <= pCardsRank->m_vecRank[nlstID].back()->x+71
&& point.y >= pCardsRank->m_vecRank[nlstID].back()->y && point.y <= pCardsRank->m_vecRank[nlstID].back()->y+96)
{
// жǷ
if(pCardsRank->m_vecRank[nlstID].back()->pCards->m_nCardsNum-1 == lstCursorCards.front()->pCards->m_nCardsNum)
{
return true;
}
}
}
}
return false;
}
//
void CAAAARule::UpDatePos(CCardsRank* pCardsRank, int nlstID)
{
int j=0;
list<Node*>::iterator ite = pCardsRank->m_vecRank[nlstID].begin();
while(ite != pCardsRank->m_vecRank[nlstID].end())
{
(*ite)->x = 10+81*nlstID;
(*ite)->y = 10+j*20;
++j;
++ite;
}
//
this->DeleteLine(pCardsRank,nlstID);
}
void CAAAARule::DeleteLine(CCardsRank* pCardsRank, int nlstID)
{
if(pCardsRank->m_vecRank[nlstID].size() >= 13 && pCardsRank->m_vecRank[nlstID].back()->pCards->m_nCardsNum == 1)
{
int num = 1;
list<Node*>::reverse_iterator rev_ite = pCardsRank->m_vecRank[nlstID].rbegin();
//
for(int i=0;i<13;i++)
{
// б Խ
if((*rev_ite)->bFlag == false)
return;
// Dz
if((*rev_ite)->pCards->m_nCardsNum != num)
return;
++rev_ite;
++num;
}
//
list<Node*>::iterator ite = rev_ite.base();
while(ite != pCardsRank->m_vecRank[nlstID].end())
{
delete(*ite);
ite = pCardsRank->m_vecRank[nlstID].erase(ite);
}
// һƷ
if(pCardsRank->m_vecRank[nlstID].empty() == false)
pCardsRank->m_vecRank[nlstID].back()->bFlag = true;
}
} | true |
bf7403b9976ae63dfbba4f93f904ecf0764bce28 | C++ | MuraliMohanRanganath/GameEngine | /Engine/Physics.h | UTF-8 | 1,245 | 2.625 | 3 | [] | no_license | #pragma once
#ifndef PHYSICS_H
#define PHYSICS_H
#include <vector>
#include "Vector.h"
#include "GameObject.h"
#include "SmartPointer.h"
namespace Engine
{
struct PhysicsInfo
{
double mass;
double coefficientOfDrag;
Engine::Vector forces;
SmartPointer<GameObject> object;
};
class Physics
{
public:
inline static Physics* getInstance();
inline PhysicsInfo* addObjectToPhysicSystem(SmartPointer<GameObject>& obj,double mass, double coefficientOfDrag,Engine::Vector force = Engine::Vector::VectorZero);
inline PhysicsInfo* createDelayedPhysicObject(SmartPointer<GameObject>& obj, double mass, double coefficientOfDrag, Engine::Vector force = Engine::Vector::VectorZero);
inline void addPhysicsInfo(PhysicsInfo* info);
void removeObject(SmartPointer<GameObject>& object );
void update(double dt);
void update(PhysicsInfo * object1,PhysicsInfo * object2,double dt);
bool init();
void shutDown();
void addForce(SmartPointer<GameObject>& object, Engine::Vector force);
private:
std::vector<PhysicsInfo*>physicObjects;
static Physics* myInstance;
Physics() {};
Physics(const Physics& physics) {};
Physics& operator=(const Physics& physics) {};
};
}
#include "Physics_Ini.h"
#endif | true |
409172941855060b0e93b5161a557b44e7c6b73f | C++ | zkrami/SuperLibrary | /C++/Algorithms/String/split.cpp | UTF-8 | 479 | 3.640625 | 4 | [
"Apache-2.0"
] | permissive | #include <vector>
#include <string>
/**
* Splits string into vector
*
* @param string str
* @return vector<std::string>
*/
std::vector<std::string> split(std::string str, char delimiter)
{
std::vector<std::string> words;
int i = 0, j = 0;
while (str[i] != '\0') {
if (str[i] == delimiter) {
words.push_back(str.substr(j, i - j));
j = i + 1;
}
i++;
}
words.push_back(str.substr(j));
return words;
} | true |
9b25b50d6d8cc1ea2b9fcb07d7ef1bf0da5417c3 | C++ | zm2417/luogu-cpp | /1739.cpp | UTF-8 | 639 | 3.25 | 3 | [] | no_license | #include <iostream>
#include <stack>
using namespace std;
int main()
{
string word;
cin >> word;
stack<char> s;
for (int i = 0; i < word.size(); i++)
{
if (word[i] == '(')
s.push('(');
else if (word[i] == ')')
{
if (s.empty())
{
cout << "NO";
return 0;
}
else
{
s.pop();
}
}
else if (word[i] == '@')
{
break;
}
}
if (s.empty())
cout << "YES";
else
{
cout << "NO";
}
return 0;
} | true |
76d599cb93eea3745513ddb83e1c7736c6551793 | C++ | kbaras2020/Lab7_2020_1 | /Lab7_2020_1/Main.cpp | UTF-8 | 1,215 | 3.828125 | 4 | [] | no_license | #include <iostream>
using namespace std;
#include "Fila.h"
int main()
{
Fila f;
Nova(f);
bool w = true;
while (w) {
cout << "\nEscolha uma opcao:\n";
cout << "1) Entra\n";
cout << "2) Sai\n";
cout << "3) Primeiro\n";
cout << "4) Comprimento\n";
cout << "5) Mostra\n";
cout << "0) Terminar\n";
cout << "Escolha uma opcao : ";
int escolha;
cin >> escolha;
int elemento;
switch (escolha) {
case 1: //Entra
cout << "Coloque um elemento na fila: ";
cin >> elemento;
Entra(f, elemento);
break;
case 2: //Sai
try {
Sai(f);
}
catch (int e) {
cout << "Ocorreu excepcao numero " << e << ". Fila vazia! " << endl;
}
break;
case 3: //Primeiro
try {
cout << Primeiro(f) << " e' o primeiro elemento da fila." << endl;
}
catch (int e) {
cout << "Ocorreu excepcao numero " << e << ". Fila vazia! " << endl;
}
break;
case 4: //Comprimento
cout << endl;
cout << "Comprimento: " << Comprimento(f) << endl;
break;
case 5: //Mostra
Escreve(f);
break;
case 0: //Terminar
w = false;
break;
default:
cout << "\n\n***Opcao invalida*** \n***Tente de novo***\n\n";
cin.sync();
cin.clear();
}
}
return 0;
} | true |
18fd5bbb819f97ef2d4470570d86bedb1be48481 | C++ | romiltendulkar/GameOfTheAmazonsV2 | /GameOfTheAmazons/GameOfTheAmazons/Solver.cpp | UTF-8 | 214,464 | 3.3125 | 3 | [
"Apache-2.0"
] | permissive | //////////////////////////////////////////////////////////////
/**
@file Solver.cpp
@author Romil Tendulkar
@date 12/06/2019
@brief This class will be used to Solve the board
based on the files given. Taking input from one
and writing to another file
*/
//////////////////////////////////////////////////////////////
#include <algorithm>
#include "Solver.h"
Solver::Solver(FILE* pInFile, FILE* pOutFile)
{
mInFile = pInFile; //initialize to the input stream pointer
mOutFile = pOutFile; //initialize to the output stream pointer
mCurrentBoard = nullptr; //As no board is made yet, this is nullptr
mBestAI = nullptr;
mBestPlayer = nullptr;
isSatisfied = false;
}
Solver::~Solver()
{
}
void Solver::MakeBoard()
{
int nRows, nCols;
//read the first two integers from the stream as the number of rows and columns.
fscanf_s(mInFile, "%i", &nRows);
fscanf_s(mInFile, "%i", &nCols);
//allocate memory for the board based on the number of rows and columns
mCurrentBoard = new Board(nRows, nCols);
for (int i = 0; i < nRows; ++i)
{
for (int j = 0; j < nCols; ++j)
{
//read each board position.
int temp;
fscanf_s(mInFile, "%i", &temp);
mCurrentBoard->mBoardVec->at(i).at(j) = temp;
}
}
//mCurrentBoard->PrintBoard();
}
void Solver::Solve()
{
while (!isSatisfied)
{
mCurrentBoard->PrintBoard();
Search(mCurrentBoard, 0, 0);
if (mBestAI != nullptr)
{
std::cout << "\n Best Move for AI has Scope: " << mBestAI->Scope;
std::cout << "\n The best move for player is from (" << mBestAI->mOrigX << "," << mBestAI->mOrigY
<< ") to (" << mBestAI->mNewX << " ," << mBestAI->mNewY
<< ") shooting at " << " (" << mBestAI->mShootX << " ," << mBestAI->mShootY << ")";
}
if (mBestPlayer != nullptr)
{
std::cout << "\n Best Move for Player has Scope: " << mBestPlayer->Scope;
std::cout << "\n The best move for player is from (" << mBestPlayer->mOrigX << "," << mBestPlayer->mOrigY
<< ") to (" << mBestPlayer->mNewX << " ," << mBestPlayer->mNewY
<< ") shooting at " << " (" << mBestPlayer->mShootX << " ," << mBestPlayer->mShootY << ")";
}
char input;
std::cout << "\n Do you want to make a move? Press Y to confirm: ";
std::cin >> input;
if (input == 'y' || input == 'Y')
{
char insideInput;
std::cout << "\n Do you want to make best move for player? Press Y to confirm: ";
std::cin >> insideInput;
if (insideInput == 'y' || insideInput == 'Y')
{
mCurrentBoard->UpdateBoard(mBestAI);
mCurrentBoard->UpdateBoard(mBestPlayer);
}
else
{
mCurrentBoard->UpdateBoard(mBestAI);
mCurrentBoard->PrintBoard();
bool moveable = false;
int oX, oY, nX, nY, sX, sY;
while (!moveable)
{
std::cout << "\nEnter x position of piece to move:";
std::cin >> oX;
std::cout << "\nEnter y position of piece to move:";
std::cin >> oY;
if (mCurrentBoard->mBoardVec->at(oX).at(oY) == BOARD_WHITE)
{
moveable = true;
}
else
{
std::cout << "\n Enter valid position!";
}
}
moveable = false;
while (!moveable)
{
std::cout << "\nEnter new x position :";
std::cin >> nX;
std::cout << "\nEnter new y position :";
std::cin >> nY;
bool hitwall = false;
int cx = oX, cy = oY;
if (nX == oX && nY == oY)
{
std::cout << "\n Enter valid position!";
}
else
{
while (!hitwall)
{
if (nX >= oX)
{
if (cx < nX)
{
cx++;
}
}
else
{
if (cx > nX)
{
cx--;
}
}
if (nY >= oY)
{
if (cy< nY)
{
cy++;
}
}
else
{
if (cy > nY)
{
cy--;
}
}
if (mCurrentBoard->mBoardVec->at(cx).at(cy) == BOARD_WALL)
{
hitwall = true;
}
else
{
if (cx == nX && cy == nY)
{
if (mCurrentBoard->mBoardVec->at(cx).at(cy) == BOARD_CLEAR)
{
moveable = true;
hitwall = true;
}
}
}
}
if (!moveable)
{
std::cout << "\n Enter valid position!";
}
}
}
moveable = false;
while (!moveable)
{
std::cout << "\nEnter x position to shoot:";
std::cin >> sX;
std::cout << "\nEnter y position to shoot:";
std::cin >> sY;
bool hitwall = false;
int cx = nX, cy = nY;
if (sX == nX && sY == nY)
{
std::cout << "\n Enter valid position!";
}
else if (sX == oX && sY == oY)
{
moveable = true;
}
else
{
while (!hitwall)
{
if (sX >= nX)
{
if (cx < sX)
{
cx++;
}
}
else
{
if (cx > sX)
{
cx--;
}
}
if (sY >= sY)
{
if (cy < sY)
{
cy++;
}
}
else
{
if (cy > sY)
{
cy--;
}
}
if (mCurrentBoard->mBoardVec->at(cx).at(cy) == BOARD_WALL)
{
hitwall = true;
}
else
{
if (cx == sX && cy == sY)
{
if (mCurrentBoard->mBoardVec->at(cx).at(cy) == BOARD_CLEAR)
{
moveable = true;
hitwall = true;
}
}
}
}
if (!moveable)
{
std::cout << "\n Enter valid position!";
}
}
}
moveable = false;
MoveClass* mMove = new MoveClass(oX, oY, nX, nY, sX, sY,BOARD_WHITE);
mCurrentBoard->UpdateBoard(mMove);
}
}
else
{
isSatisfied = true;
}
}
}
int Solver::Search(Board *pBoard, int depthTo, int currDepth)
{
bool isMax = false; //used to define the whether the player is the AI.
if ((currDepth % 2) == 0)
{
isMax = true;
int currScope = pBoard->FindScope(BOARD_BLACK);
if (currScope == 0)
{
//if the ai has no moves available, see if the human player has any.
int temp = pBoard->FindScope(BOARD_WHITE);
if (temp == 0)
{
return -1; //this means human player played last, winning by 1 move
}
else
{
return -temp; //The human player winning by more than 1 move.
}
}
if (depthTo != 0)
{
if (depthTo == currDepth)
{
return currScope;
}
}
}
else
{
int currScope = pBoard->FindScope(BOARD_WHITE);
if (currScope == 0)
{
int temp = pBoard->FindScope(BOARD_BLACK);
if (temp == 0)
{
return 1;
}
else
{
return temp;
}
}
if (depthTo != 0)
{
if (depthTo == currDepth)
{
return currScope;
}
}
}
Board *tBoard = new Board(pBoard);
MoveClass* mMove;
if (isMax)
{
mMove = new MoveClass(GetBestMove(pBoard, BOARD_BLACK, depthTo, currDepth));
//GetBestMove(pBoard, BOARD_BLACK);
if (currDepth == 0)
{
mBestAI = new MoveClass(mMove);
Board* temp = new Board(pBoard);
temp->UpdateBoard(mMove);
BSearch(temp, depthTo, 1);
}
//std::cout << "\n Scope is: " << mMove->Scope;
return mMove->Scope;
}
else
{
mMove = new MoveClass(GetBestMove(pBoard, BOARD_WHITE, depthTo, currDepth));
return mMove->Scope;
}
//return 0;
}
int Solver::BSearch(Board* pBoard, int depthTo, int currDepth)
{
bool isMax = false;
if ((currDepth % 2) == 0)
{
isMax = true;
int currScope = pBoard->FindScope(BOARD_BLACK);
if (currScope == 0)
{
int temp = pBoard->FindScope(BOARD_WHITE);
if (temp == 0)
{
return -1;
}
else
{
return -temp;
}
}
if (depthTo != 0)
{
if (depthTo == currDepth)
{
return currScope;
}
}
}
else
{
int currScope = pBoard->FindScope(BOARD_WHITE);
if (currScope == 0)
{
int temp = pBoard->FindScope(BOARD_BLACK);
if (temp == 0)
{
return 1;
}
else
{
return temp;
}
}
if (depthTo != 0)
{
if (depthTo == currDepth)
{
return currScope;
}
}
}
Board* tBoard = new Board(pBoard);
MoveClass* mMove;
if (isMax)
{
mMove = new MoveClass(GetBestMove(pBoard, BOARD_BLACK, depthTo, currDepth));
return mMove->Scope;
}
else
{
mMove = new MoveClass(GetBestMove(pBoard, BOARD_WHITE, depthTo, currDepth));
if (currDepth == 1)
{
mBestPlayer = new MoveClass(mMove);
}
return mMove->Scope;
}
//return 0;
}
MoveClass* Solver::GetBestMove(Board *pBoard, BoardIDs currPlayer, int depthTo, int currDepth)
{
int mNumRows = pBoard->mNumRows;
int mNumCols = pBoard->mNumCols;
MoveClass *temp = new MoveClass(0,0,0,0,0,0,currPlayer);
bool isMoveSet = false;
for (int counter1 = 0; counter1 < mNumRows; ++counter1)
{
for (int counter2 = 0; counter2 < mNumCols; ++counter2)
{
if (pBoard->mBoardVec->at(counter1).at(counter2) == currPlayer)
{
//Calculate Scope
int newX, newY;
bool hitWall;
//Check in the upwards direction
newX = counter1;
newY = counter2 - 1;
hitWall = false;
while (newY >= 0 && !hitWall)
{
if (pBoard->mBoardVec->at(newX).at(newY) == BOARD_CLEAR)
{
//Calculate shooting scope
int shootX, shootY;
bool shitWall;
//check in the upwards direction
shootX = newX;
shootY = newY - 1;
shitWall = false;
while (shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY--;
}
//calculate shooting in downwards
shootX = newX;
shootY = newY + 1;
shitWall = false;
while (shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY++;
}
//calculate shooting in left
shootX = newX - 1;
shootY = newY;
shitWall = false;
while (shootX >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
}
//calculate shooting in right
shootX = newX + 1;
shootY = newY;
shitWall = false;
while (shootX < mNumCols && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
}
//calculate shooting in the -- direction
shootX = newX - 1;
shootY = newY - 1;
shitWall = false;
while (shootX >= 0 && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY--;
}
//calculate shooting in the -+ direction
shootX = newX - 1;
shootY = newY + 1;
shitWall = false;
while (shootX >= 0 && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY++;
}
//calculate shooting in the ++ direction
shootX = newX + 1;
shootY = newY + 1;
shitWall = false;
while (shootX < mNumCols && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY++;
}
//calculate shooting in the +- direction
shootX = newX + 1;
shootY = newY - 1;
shitWall = false;
while (shootX < mNumCols && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY--;
}
}
else
{
hitWall = true;
}
newY--;
}
//Check in the Downwards direction
newX = counter1;
newY = counter2 + 1;
hitWall = false;
while (newY < mNumRows && !hitWall)
{
if (pBoard->mBoardVec->at(newX).at(newY) == BOARD_CLEAR)
{
//Calculate shooting scope
int shootX, shootY;
bool shitWall;
//check in the upwards direction
shootX = newX;
shootY = newY - 1;
shitWall = false;
while (shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY--;
}
//calculate shooting in downwards
shootX = newX;
shootY = newY + 1;
shitWall = false;
while (shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY++;
}
//calculate shooting in left
shootX = newX - 1;
shootY = newY;
shitWall = false;
while (shootX >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
}
//calculate shooting in right
shootX = newX + 1;
shootY = newY;
shitWall = false;
while (shootX < mNumCols && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
}
//calculate shooting in the -- direction
shootX = newX - 1;
shootY = newY - 1;
shitWall = false;
while (shootX >= 0 && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY--;
}
//calculate shooting in the -+ direction
shootX = newX - 1;
shootY = newY + 1;
shitWall = false;
while (shootX >= 0 && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY++;
}
//calculate shooting in the ++ direction
shootX = newX + 1;
shootY = newY + 1;
shitWall = false;
while (shootX < mNumCols && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY++;
}
//calculate shooting in the +- direction
shootX = newX + 1;
shootY = newY - 1;
shitWall = false;
while (shootX < mNumCols && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY--;
}
}
else
{
hitWall = true;
}
newY++;
}
//Check in Right Direction
newX = counter1 + 1;
newY = counter2;
hitWall = false;
while (newX < mNumCols && !hitWall)
{
if (pBoard->mBoardVec->at(newX).at(newY) == BOARD_CLEAR)
{
//Calculate shooting scope
int shootX, shootY;
bool shitWall;
//check in the upwards direction
shootX = newX;
shootY = newY - 1;
shitWall = false;
while (shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY--;
}
//calculate shooting in downwards
shootX = newX;
shootY = newY + 1;
shitWall = false;
while (shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY++;
}
//calculate shooting in left
shootX = newX - 1;
shootY = newY;
shitWall = false;
while (shootX >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
}
//calculate shooting in right
shootX = newX + 1;
shootY = newY;
shitWall = false;
while (shootX < mNumCols && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
}
//calculate shooting in the -- direction
shootX = newX - 1;
shootY = newY - 1;
shitWall = false;
while (shootX >= 0 && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY--;
}
//calculate shooting in the -+ direction
shootX = newX - 1;
shootY = newY + 1;
shitWall = false;
while (shootX >= 0 && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY++;
}
//calculate shooting in the ++ direction
shootX = newX + 1;
shootY = newY + 1;
shitWall = false;
while (shootX < mNumCols && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY++;
}
//calculate shooting in the +- direction
shootX = newX + 1;
shootY = newY - 1;
shitWall = false;
while (shootX < mNumCols && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY--;
}
}
else
{
hitWall = true;
}
newX++;
}
//Check in the Left Direction
newX = counter1 - 1;
newY = counter2;
hitWall = false;
while (newX >= 0 && !hitWall)
{
if (pBoard->mBoardVec->at(newX).at(newY) == BOARD_CLEAR)
{
//Calculate shooting scope
int shootX, shootY;
bool shitWall;
//check in the upwards direction
shootX = newX;
shootY = newY - 1;
shitWall = false;
while (shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY--;
}
//calculate shooting in downwards
shootX = newX;
shootY = newY + 1;
shitWall = false;
while (shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY++;
}
//calculate shooting in left
shootX = newX - 1;
shootY = newY;
shitWall = false;
while (shootX >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
}
//calculate shooting in right
shootX = newX + 1;
shootY = newY;
shitWall = false;
while (shootX < mNumCols && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
}
//calculate shooting in the -- direction
shootX = newX - 1;
shootY = newY - 1;
shitWall = false;
while (shootX >= 0 && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY--;
}
//calculate shooting in the -+ direction
shootX = newX - 1;
shootY = newY + 1;
shitWall = false;
while (shootX >= 0 && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY++;
}
//calculate shooting in the ++ direction
shootX = newX + 1;
shootY = newY + 1;
shitWall = false;
while (shootX < mNumCols && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY++;
}
//calculate shooting in the +- direction
shootX = newX + 1;
shootY = newY - 1;
shitWall = false;
while (shootX < mNumCols && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY--;
}
}
else
{
hitWall = true;
}
newX--;
}
//Check in the -- Direction
newX = counter1 - 1;
newY = counter2 - 1;
hitWall = false;
while (newX >= 0 && newY >= 0 && !hitWall)
{
if (pBoard->mBoardVec->at(newX).at(newY) == BOARD_CLEAR)
{
//Calculate shooting scope
int shootX, shootY;
bool shitWall;
//check in the upwards direction
shootX = newX;
shootY = newY - 1;
shitWall = false;
while (shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY--;
}
//calculate shooting in downwards
shootX = newX;
shootY = newY + 1;
shitWall = false;
while (shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY++;
}
//calculate shooting in left
shootX = newX - 1;
shootY = newY;
shitWall = false;
while (shootX >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
}
//calculate shooting in right
shootX = newX + 1;
shootY = newY;
shitWall = false;
while (shootX < mNumCols && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
}
//calculate shooting in the -- direction
shootX = newX - 1;
shootY = newY - 1;
shitWall = false;
while (shootX >= 0 && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY--;
}
//calculate shooting in the -+ direction
shootX = newX - 1;
shootY = newY + 1;
shitWall = false;
while (shootX >= 0 && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY++;
}
//calculate shooting in the ++ direction
shootX = newX + 1;
shootY = newY + 1;
shitWall = false;
while (shootX < mNumCols && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY++;
}
//calculate shooting in the +- direction
shootX = newX + 1;
shootY = newY - 1;
shitWall = false;
while (shootX < mNumCols && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY--;
}
}
else
{
hitWall = true;
}
newX--;
newY--;
}
//Check in the ++ Direction
newX = counter1 + 1;
newY = counter2 + 1;
hitWall = false;
while (newX < mNumCols && newY < mNumRows && !hitWall)
{
if (pBoard->mBoardVec->at(newX).at(newY) == BOARD_CLEAR)
{
//Calculate shooting scope
int shootX, shootY;
bool shitWall;
//check in the upwards direction
shootX = newX;
shootY = newY - 1;
shitWall = false;
while (shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY--;
}
//calculate shooting in downwards
shootX = newX;
shootY = newY + 1;
shitWall = false;
while (shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY++;
}
//calculate shooting in left
shootX = newX - 1;
shootY = newY;
shitWall = false;
while (shootX >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
}
//calculate shooting in right
shootX = newX + 1;
shootY = newY;
shitWall = false;
while (shootX < mNumCols && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
}
//calculate shooting in the -- direction
shootX = newX - 1;
shootY = newY - 1;
shitWall = false;
while (shootX >= 0 && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY--;
}
//calculate shooting in the -+ direction
shootX = newX - 1;
shootY = newY + 1;
shitWall = false;
while (shootX >= 0 && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY++;
}
//calculate shooting in the ++ direction
shootX = newX + 1;
shootY = newY + 1;
shitWall = false;
while (shootX < mNumCols && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY++;
}
//calculate shooting in the +- direction
shootX = newX + 1;
shootY = newY - 1;
shitWall = false;
while (shootX < mNumCols && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY--;
}
}
else
{
hitWall = true;
}
newX++;
newY++;
}
//Check in the -+ Direction
newX = counter1 - 1;
newY = counter2 + 1;
hitWall = false;
while (newX >= 0 && newY < mNumRows && !hitWall)
{
if (pBoard->mBoardVec->at(newX).at(newY) == BOARD_CLEAR)
{
//Calculate shooting scope
int shootX, shootY;
bool shitWall;
//check in the upwards direction
shootX = newX;
shootY = newY - 1;
shitWall = false;
while (shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY--;
}
//calculate shooting in downwards
shootX = newX;
shootY = newY + 1;
shitWall = false;
while (shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY++;
}
//calculate shooting in left
shootX = newX - 1;
shootY = newY;
shitWall = false;
while (shootX >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
}
//calculate shooting in right
shootX = newX + 1;
shootY = newY;
shitWall = false;
while (shootX < mNumCols && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
}
//calculate shooting in the -- direction
shootX = newX - 1;
shootY = newY - 1;
shitWall = false;
while (shootX >= 0 && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY--;
}
//calculate shooting in the -+ direction
shootX = newX - 1;
shootY = newY + 1;
shitWall = false;
while (shootX >= 0 && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY++;
}
//calculate shooting in the ++ direction
shootX = newX + 1;
shootY = newY + 1;
shitWall = false;
while (shootX < mNumCols && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY++;
}
//calculate shooting in the +- direction
shootX = newX + 1;
shootY = newY - 1;
shitWall = false;
while (shootX < mNumCols && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY--;
}
}
else
{
hitWall = true;
}
newX--;
newY++;
}
//Check in the +- Direction
newX = counter1 + 1;
newY = counter2 - 1;
hitWall = false;
while (newX < mNumCols && newY >= 0 && !hitWall)
{
if (pBoard->mBoardVec->at(newX).at(newY) == BOARD_CLEAR)
{
//Calculate shooting scope
int shootX, shootY;
bool shitWall;
//check in the upwards direction
shootX = newX;
shootY = newY - 1;
shitWall = false;
while (shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY--;
}
//calculate shooting in downwards
shootX = newX;
shootY = newY + 1;
shitWall = false;
while (shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootY++;
}
//calculate shooting in left
shootX = newX - 1;
shootY = newY;
shitWall = false;
while (shootX >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
}
//calculate shooting in right
shootX = newX + 1;
shootY = newY;
shitWall = false;
while (shootX < mNumCols && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
}
//calculate shooting in the -- direction
shootX = newX - 1;
shootY = newY - 1;
shitWall = false;
while (shootX >= 0 && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY--;
}
//calculate shooting in the -+ direction
shootX = newX - 1;
shootY = newY + 1;
shitWall = false;
while (shootX >= 0 && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX--;
shootY++;
}
//calculate shooting in the ++ direction
shootX = newX + 1;
shootY = newY + 1;
shitWall = false;
while (shootX < mNumCols && shootY < mNumRows && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY++;
}
//calculate shooting in the +- direction
shootX = newX + 1;
shootY = newY - 1;
shitWall = false;
while (shootX < mNumCols && shootY >= 0 && !shitWall)
{
if (pBoard->mBoardVec->at(shootX).at(shootY) == BOARD_CLEAR)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else if (pBoard->mBoardVec->at(shootX).at(shootY) == currPlayer && shootX == counter1 && shootY == counter2)
{
MoveClass* mt = new MoveClass(counter1, counter2, newX, newY, shootX, shootY, currPlayer);
Board* tBoard = new Board(pBoard);
tBoard->UpdateBoard(mt);
mt->Scope = Search(tBoard, depthTo, currDepth + 1);
if (!isMoveSet)
{
isMoveSet = true;
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
else
{
if (currPlayer == BOARD_BLACK)
{
if (temp->Scope < mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
else
{
if (temp->Scope > mt->Scope)
{
temp->mOrigX = mt->mOrigX;
temp->mOrigY = mt->mOrigY;
temp->mNewX = mt->mNewX;
temp->mNewY = mt->mNewY;
temp->mShootX = mt->mShootX;
temp->mShootY = mt->mShootY;
temp->Scope = mt->Scope;
}
}
}
}
else
{
shitWall = true;
}
shootX++;
shootY--;
}
}
else
{
hitWall = true;
}
newX++;
newY--;
}
}
}
}
return temp;
} | true |
4d4d699babe8e2966e8420b6bcc45ddacf1e4163 | C++ | AnsBal/fasttp-library | /include/dyntrace/util/flag.hpp | UTF-8 | 1,425 | 3.46875 | 3 | [] | no_license | /**
* Adds flag operators and check for an enum type
*/
#ifndef DYNTRACE_UTIL_FLAG_HPP_
#define DYNTRACE_UTIL_FLAG_HPP_
#include <type_traits>
namespace dyntrace
{
template<typename E>
struct is_flag_enum : std::false_type {};
template<typename E>
constexpr bool is_flag_enum_v = is_flag_enum<E>::value;
template<typename E, typename T>
using enable_if_flag_enum_t = std::enable_if_t<is_flag_enum_v<E>, T>;
template<typename E>
constexpr enable_if_flag_enum_t<E, E> operator|(E e1, E e2) noexcept
{
using I = typename std::underlying_type<E>::type;
return static_cast<E>(static_cast<I>(e1) | static_cast<I>(e2));
}
template<typename E>
constexpr enable_if_flag_enum_t<E, E> operator&(E e1, E e2) noexcept
{
using I = typename std::underlying_type<E>::type;
return static_cast<E>(static_cast<I>(e1) & static_cast<I>(e2));
}
template<typename E>
constexpr enable_if_flag_enum_t<E, E&> operator|=(E& e1, E e2) noexcept
{
return (e1 = e1 | e2);
}
template<typename E>
constexpr enable_if_flag_enum_t<E, E&> operator&=(E& e1, E e2) noexcept
{
return (e1 = e1 & e2);
}
template<typename E>
constexpr enable_if_flag_enum_t<E, bool> flag(E e, E f) noexcept
{
using I = typename std::underlying_type<E>::type;
return static_cast<I>(e & f) != 0;
}
}
#endif | true |
afc2bf227f02fc37368ab26267d60aaba03da480 | C++ | boulware/color-c | /src/bitmap.cpp | UTF-8 | 3,394 | 2.90625 | 3 | [] | no_license | #include "bitmap.h"
#include "math.h"
#include "util.h"
#include "sprite.h"
Bitmap
AllocBitmap(u32 width, u32 height)
{
Bitmap bitmap;
bitmap.width = width;
bitmap.height = height;
bitmap.pixels = (BgraPixel*)malloc(sizeof(BgraPixel)*width*height);
return bitmap;
}
void
DeallocBitmap(Bitmap *bitmap)
{
if(bitmap->pixels != nullptr)
{
free(bitmap->pixels);
}
*bitmap = {};
}
void
Blit(Bitmap src, Bitmap dst, Vec2i pos)
{
// Copy row-by-row
for(size_t y=0; y<src.height; y++)
{
for(size_t x=0; x<src.width; x++)
{
BgraPixel src_pixel = src.pixels[x + y*src.width];
BgraPixel &dst_pixel = dst.pixels[(pos.x+x) + (pos.y+y)*dst.width];
//if(src_pixel.a != 0) dst_pixel = src_pixel;
}
}
}
void
FillBitmap(Bitmap target, BgraPixel color)
{
for(size_t i=0; i<target.width*target.height; i++)
{
target.pixels[i] = color;
}
}
// Byte offsets into .bmp files
namespace bmp {
static const int signature = 0x0;
static const int filesize = 0x2;
static const int data_offset = 0xA;
static const int width = 0x12;
static const int height = 0x16;
static const int bpp = 0x1C;
static const int compression = 0x1E;
#pragma pack(push, 1)
struct Header
{
// "Header"
char signature[2];
u32 filesize;
u32 reserved_header;
u32 data_offset;
// "InfoHeader"
u32 infoheader_size;
u32 bmp_width;
u32 bmp_height;
u16 planes;
u16 bits_per_pixel;
u32 compression;
u32 image_size;
u32 x_pixels_per_m;
u32 y_pixels_per_m;
u32 colors_used;
u32 important_colors;
};
#pragma pack(pop)
}
Bitmap LoadArgbBitmapFromFile(const char *filename)
{
Bitmap bitmap = {};
//u32 buffer_size = 10000000;
//u8 *buffer = (u8*)malloc(buffer_size);
Buffer buffer;
bool load_success = platform->LoadFileIntoSizedBufferAndNullTerminate(filename, &buffer);
if(!load_success)
{
return bitmap;
}
bmp::Header header = *(bmp::Header*)buffer.data;
if(!CompareBytesN(header.signature, "BM", 2))
{
Log("Invalid file format signature in bitmap file (\"%s\")", filename);
goto FINAL;
}
if(header.bits_per_pixel != 32)
{
Log("Unsupported bmp file format (format: bpp %u, compression %u) (file: \"%s\")",
header.bits_per_pixel, header.compression, filename);
goto FINAL;
}
bitmap.width = header.bmp_width;
bitmap.height = header.bmp_height;
u32 data_offset = header.data_offset;
u64 bytes_per_pixel = 4; // We've already guaranteed bits/pixel = 32
u64 bytes_per_row = bitmap.width * bytes_per_pixel;
bitmap.pixels = (BgraPixel*)malloc(4 * bitmap.width * bitmap.height);
for(int i=0; i<bitmap.height; i++)
{
// BMPs are stored bottom to top, so we need (bitmap.height-1)-i to flip it when loading into memory.
CopyMemoryBlock((u8*)bitmap.pixels+((bitmap.height-1)-i)*bytes_per_row, (u8*)buffer.data+data_offset+i*bytes_per_row, bytes_per_row);
}
FINAL:
FreeBuffer(&buffer);
return bitmap;
}
Sprite
LoadBitmapFileIntoSprite(const char *filename, Align align = c::align_topleft)
{
Bitmap bitmap = LoadArgbBitmapFromFile(filename);
Sprite sprite = {};
sprite.texture = GenerateAndBindTexture();
sprite.size = {(float)bitmap.width, (float)bitmap.height};
if(align == c::align_center)
{
sprite.origin = 0.5f * sprite.size;
}
gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bitmap.width, bitmap.height,
0, GL_BGRA, GL_UNSIGNED_BYTE, bitmap.pixels);
DeallocBitmap(&bitmap);
return sprite;
} | true |
51c0652e39bbf10572b1929c0b11d761ff241ee4 | C++ | Manvi-tech/Data-Structures | /Queue/queueUsingList.cpp | UTF-8 | 1,076 | 3.8125 | 4 | [] | no_license |
// queue using linked list
#include <bits/stdc++.h>
using namespace std;
class Node{
public:
int data;
Node* next;
Node(int x){
this->data = x;
this->next = NULL;
}
};
class queueUsingList{
public:
Node* head;
Node* tail;
int listSize;
queueUsingList(){
this->head=NULL;
this->tail=NULL;
this->listSize=0;
}
void push(int x){
if(head==NULL){
head = new Node(x);
tail=head;
}else{
tail->next = new Node(x);
tail=tail->next;
}
listSize++;
return;
}
void pop(){
if(head==NULL){return;}
Node* temp=head;
head=head->next;
temp->next=NULL;
cout<<temp->data<<" is popped"<<endl;
delete temp;
listSize--;
return;
}
int top(){
if(head==NULL){return -1;}
return head->data;
}
int size(){
return listSize;
}
};
int main() {
queueUsingList que;
que.push(5);
que.push(10);
cout<<que.top()<<endl;
que.pop();
cout<<que.size()<<endl;
return 0;
} | true |
6c0574ac6c77c8e7d81f33ecb2a13f66ffdfc0f0 | C++ | rpugase/Algorithms_Hillel | /first/first_test.cpp | UTF-8 | 2,521 | 3.109375 | 3 | [] | no_license | #include <iostream>
#include <vector>
#include "first_lesson.h"
#include <cassert>
using namespace std;
void test_is_prime();
void test_binary_search();
void test_count_n();
void test_count_logn();
void test_sqrt();
void test_reverse_array();
int main() {
test_is_prime();
test_binary_search();
test_count_n();
test_count_logn();
test_reverse_array();
test_sqrt();
return 0;
}
void test_is_prime() {
assert(is_prime(2)); // true;
assert(!is_prime(1)); // false;
assert(is_prime(13)); // true;
assert(is_prime(97)); // true;
assert(is_prime(1000000007)); // true;
assert(!is_prime(1000000011)); // false;
cout << __func__ << " PASSED" << endl;
}
void test_binary_search() {
vector<int> arr = {1, 4, 8, 11, 21, 23, 24, 64, 70, 84, 125, 704, 1099, 1200, 1201, 1202, 2000};
assert(binary_search(arr, 8)); // YES
assert(!binary_search(arr, 10)); // NO
assert(binary_search(arr, 70)); // YES
assert(!binary_search(arr, 1098)); // NO
assert(binary_search(arr, 1202)); // YES
assert(!binary_search(arr, 1999)); // NO
cout << __func__ << " PASSED" << endl;
}
void test_count_n() {
vector<int> arr = {1, 4, 8, 11, 21, 23, 24, 64, 70, 84, 125, 704, 1099, 1200, 1201, 1202, 2000};
assert(count_n(arr, 1, 10) == 3); // 3
assert(count_n(arr, 200, 700) == 0); // 0
assert(count_n(arr, 20, 100) == 6); // 6
assert(count_n(arr, 1000, 2000) == 5); // 5
assert(count_n(arr, 84, 84) == 1); // 1
assert(count_n(arr, 2, 2002) == 16); // 16
cout << __func__ << " PASSED" << endl;
}
void test_count_logn() {
vector<int> arr = {1, 4, 8, 11, 21, 23, 24, 64, 70, 84, 125, 704, 1099, 1200, 1201, 1202, 2000};
assert(count_logn(arr, 1, 10) == 3); // 3
assert(count_logn(arr, 200, 700) == 0); // 0
assert(count_logn(arr, 20, 100) == 6); // 6
assert(count_logn(arr, 1000, 2000) == 5); // 5
assert(count_logn(arr, 84, 84) == 1); // 1
assert(count_logn(arr, 2, 2002) == 16); // 16
cout << __func__ << " PASSED" << endl;
}
void test_sqrt() {
double eps = 1e+7;
assert(int(sqrt_t(4)) == 2); // 2;
assert(int(sqrt_t(25)) == 5); // 5;
assert(int(sqrt_t(163)*eps) == int(12.76714539 * eps)); // 12.7671453
cout << __func__ << " PASSED" << endl;
}
void test_reverse_array() {
vector<int> arr = {1, 4, 8, 11, 21, 23, 24, 64, 70, 84};
assert((reverse_array(arr) == vector<int>{84, 70, 64, 24, 23, 21, 11, 8, 4, 1}));
cout << __func__ << " PASSED" << endl;
} | true |
6c0674129dd56fae0c38031ccb96785db14d9164 | C++ | ConalTyre/StudentMod | /StudentModule/Lecture.h | UTF-8 | 608 | 2.65625 | 3 | [] | no_license | #pragma once
#include <iostream>
#include "Module.h"
#include <vector>
class Lecture
{
private:
std::string id_;
std::string subjectarea_;
std::vector<Module> modules_;
public:
Lecture();
Lecture(std::string name, std::string email, std::string id, std:: string subjectarea, std::vector<Module> m);
void SetId(std::string id);
std::string Getid() const;
void Setsubjectarea(std::string subjectarea);
std::string Getsubjectarea() const;
void SetModules(std::vector<Module> m);
std::vector <Module> GetModules() const;
virtual std::string ToString () override
};
| true |
ea143dfaaefbae787f43eb231ac7b1f733e63a6f | C++ | hackboxlive/CP | /SPOJ/POWPOW2.cpp | UTF-8 | 1,241 | 2.75 | 3 | [] | no_license | #include <bits/stdc++.h>
using namespace std;
const int LIM = 1e5;
const long long MODD = 1e9 + 7;
int factors[200200];
int f[200200];
void precompute() {
factors[1] = 1;
for(int i = 2; i <= 2 * LIM; i++) {
if(factors[i] == 0) {
for(int j = i; j <= 2 * LIM; j += i) {
if(factors[j] == 0) {
factors[j] = i;
}
}
}
}
}
long long power_expo(long long a, long long n, long long modd) {
if(n == 0) {
return 1;
}
if(n == 1) {
return a;
}
long long ans = power_expo(a, n/2, modd);
ans = ans * ans;
ans %= modd;
if(n%2 == 1) {
ans = ans * a;
ans %= modd;
}
return ans;
}
void get_factors(int n, int check) {
while(n != 1) {
f[factors[n]] += check;
n /= factors[n];
}
}
int main() {
precompute();
int t;
cin >> t;
while(t--) {
long long a, b, n;
cin >> a >> b >> n;
for(int i = 1; i <= 2 * n; i++) {
f[i] = 0;
}
for(int i = 1; i <= n; i++) {
get_factors(i, -1);
get_factors(n + i, 1);
}
long long ans = 1;
for(int i = 2; i <= 2 * n; i++) {
ans *= power_expo(i, f[i], MODD - 2);
ans %= (MODD - 2);
}
cout << ans << endl;
ans = power_expo(b, ans, MODD - 1);
//cout << ans << endl;
ans = power_expo(a, ans, MODD);
cout << ans << endl;
}
return 0;
}
| true |
02fc9c205051716ccfecc90a4c7b57f512e2cd96 | C++ | theMorning/katas | /binary_search/BinarySearchTest.cpp | UTF-8 | 1,957 | 3.609375 | 4 | [
"MIT"
] | permissive | #include <sstream>
#include <gtest/gtest.h>
#include "binary_search.hpp"
TEST(BinarySearchTest, EmptyArray) {
int sorted_arr[0] = {};
int find = 0;
int found = binary_search(find, sorted_arr, 0);
ASSERT_EQ(found, -1);
}
TEST(BinarySearchTest, ArrayOfOne) {
int sorted_arr[1] = {0};
int find = 0;
int found = binary_search(find, sorted_arr, 1);
ASSERT_EQ(found, 0);
}
TEST(BinarySearchTest, ArrayOfTwoFindFirst) {
int sorted_arr[2] = {0,1};
int find = 0;
int found = binary_search(find, sorted_arr, 2);
ASSERT_EQ(found, 0);
}
TEST(BinarySearchTest, ArrayOfTwoFindSecond) {
int sorted_arr[2] = {0,1};
int find = 1;
int found = binary_search(find, sorted_arr, 2);
ASSERT_EQ(found, 1);
}
TEST(BinarySearchTest, ArrayOfThreeNotFound) {
int sorted_arr[3] = {0,1,2};
int find = 42;
int found = binary_search(find, sorted_arr, 3);
ASSERT_EQ(found, -1);
}
TEST(BinarySearchTest, ArrayOfThreeFindFirst) {
int sorted_arr[3] = {0,1,2};
int find = 0;
int found = binary_search(find, sorted_arr, 3);
ASSERT_EQ(found, 0);
}
TEST(BinarySearchTest, ArrayOfThreeFindSecond) {
int sorted_arr[3] = {0,1,2};
int find = 1;
int found = binary_search(find, sorted_arr, 3);
ASSERT_EQ(found, 1);
}
TEST(BinarySearchTest, ArrayOfThreeFindThird) {
int sorted_arr[3] = {0,1,2};
int find = 2;
int found = binary_search(find, sorted_arr, 3);
ASSERT_EQ(found, 2);
}
TEST(BinarySearchTest, ArrayOfFiveSearchLeftThenRight) {
int sorted_arr[5] = {0,1,2,4,5};
int find = 1;
int found = binary_search(find, sorted_arr, 5);
ASSERT_EQ(found, 1);
}
TEST(BinarySearchTest, ArrayOfFiveSearchRighThenLeft) {
int sorted_arr[5] = {0,1,2,4,5};
int find = 4;
int found = binary_search(find, sorted_arr, 5);
ASSERT_EQ(found, 3);
}
TEST(BinarySearchTest, RealExample) {
int sorted_arr[8] = {1, 3, 7, 20, 27, 36, 42, 79};
int find = 42;
int found = binary_search(find, sorted_arr, 8);
ASSERT_EQ(found, 6);
}
| true |
128e0ac570ef51a5b4b24b3417d5f9d8abef032b | C++ | zalabjir/MergeSort | /Merge_Sort_6.cpp | UTF-8 | 3,525 | 3.3125 | 3 | [] | no_license | #include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <chrono>
using namespace std;
class Sort {
public:
virtual void merge(vector<int> &arr, int l, int m, int p) = 0;
virtual void sort(vector<int> &arr, int l, int p) = 0;
virtual void printArray(vector<int> &arr) = 0;
};
class MergeSort : public Sort {
// Merge dvou posloupnosti (Leva + Prava)
// Prvni posloupnost arr[l..m]
// Druha posloupnost arr[m+1..p]
public:
void merge(vector<int> &arr, int l, int m, int p) {
int n1 = m - l + 1;
int n2 = p - m;
// Docas. posloupnosti
vector<int> L(n1), P(n2);
// Posli data do temp sloupcu L[] a P[]
for (int i = 0; i < n1; i++)
L[i] = arr[l + i];
for (int j = 0; j < n2; j++)
P[j] = arr[m + 1 + j];
// Merge posloupnosti zpatky do arr[l..p]
// Prvni index prvfni posl
int i = 0;
// Prvni index druhe posl
int j = 0;
// Prvni index mergle posl
int k = l;
while (i < n1 && j < n2) {
if (L[i] <= P[j]) {
arr[k] = L[i];
i++;
} else {
arr[k] = P[j];
j++;
}
k++;
}
// Zkopiruj zbytek L[], pokud E
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
// Zkopiruj zbytek P[], pokud E
while (j < n2) {
arr[k] = P[j];
j++;
k++;
}
}
// l= levy idx, p=pravy idx pod-posloupnosti arr k serazeni
void sort(vector<int> &arr, int l, int p) {
if (l >= p) {
return; //vraci rekurzivne
}
int m = (l + p - 1) / 2;
sort(arr, l, m);
sort(arr, m + 1, p);
merge(arr, l, m, p);
}
// Var Funkce
// Output zprava
void printArray(vector<int>& A) {
for (int i = 0; i < A.size(); i++)
cout << A.at(i) << " ";
}
};
vector<int> readData(string filename) {
std::fstream myfile(filename, std::ios_base::in);
vector<int> numbers;
int a;
while (myfile >> a) {
numbers.push_back(a);
}
//getchar();
return numbers;
}
// Hlavni program
int main() {
int iterations = 10; //iterations to get average from
string inputFile = "20k.txt";
vector<int> numbers = readData(inputFile);
double totalDuration = 0;
int arr_size = numbers.size();
MergeSort m;
cout << "Given array is \n";
m.printArray(numbers);
cout << "\n\n\n\n";
vector<int> tmp_array;
for (int i = 0; i < iterations; i++) {
//copy original array to a new one to have the same array every time
tmp_array = numbers;
//measuring part
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
m.sort(tmp_array, 0, numbers.size() - 1);
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
totalDuration += std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count();
}
cout << "\nSorted array is \n";
m.printArray(tmp_array);
cout << "\n\n\n\n";
cout << "avg time from " << iterations << " runs is: " << totalDuration / iterations << "[ms]" << std::endl;
return 0;
}
| true |
879b5adabe4ee94b59a776433bc2755efc2a2b6d | C++ | parasbabbar1612/CPP | /linkedlist1.cpp | UTF-8 | 1,042 | 3.875 | 4 | [] | no_license | #include<iostream>
using namespace std;
class node
{
public:
int data;
node* next;
};
node* head = NULL;
node* tail = NULL;
void addnode(int val)
{
node* temp = new node;
temp->data = val;
temp->next = NULL;
if (head == NULL || tail == NULL)
{
head = temp;
tail = temp;
temp = NULL;
}
else
{
tail->next = temp;
tail = temp;
}
}
void delnode(int v)
{
node* s = head;
int count = 0;
while (s != NULL)
{
if (s->data == v)
{
count++;
s->data = s->next->data;
s->next = s->next->next;
}
else s = s->next;
}
if (count > 0) cout << "\n Found and deleted";
else cout << "\n Not found";
cout << "\n The list after insertion and deletion is:" << endl;
}
int main()
{
int n, val, del;
cout << "\n Enter the number of nodes u want to enter";
cin >> n;
for (int i = 0; i < n; i++)
{
cout << "\n Enter node";
cin >> val;
addnode(val);
}
node* p = head;
cout << "\n Enter value to be deleted";
cin >> del;
delnode(del);
while (p != NULL)
{
cout << p->data << endl;
p = p->next;
}
} | true |
5c8580430c8dfc89a1a49873b9c26a600553acfe | C++ | anuragpratap05/pepcoding | /getmzepaths.cpp | UTF-8 | 760 | 2.875 | 3 | [] | no_license | # pepcoding#include<bits/stdc++.h>
using namespace std;
vector<string> getmzepaths(int sr, int sc, int dr, int dc)
{
if (sr == dr and sc == dc)
{
vector<string > bres;
bres.push_back(" ");
return bres;
}
vector<string> hpath;
vector<string> vpath;
if (sc < dc)
hpath = getmzepaths(sr, sc + 1, dr, dc);
if (sr < dr)
vpath = getmzepaths(sr + 1, sc, dr, dc);
vector<string> final;
for (auto hpaths : hpath)
{
final.push_back("h" + hpaths);
}
for (auto vpaths : vpath)
{
final.push_back("v" + vpaths);
}
return final;
}
int main()
{
#ifndef ONLINE_jUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
vector<string> v = getmzepaths(1, 1, 3, 3);
for (auto z : v)
{
cout << z << " ";
}
}
| true |
519def2e35db17ab5ff4ac5f9085aaab8622bfce | C++ | io-io/study-cpp | /pr2/task1.cpp | UTF-8 | 436 | 3.03125 | 3 | [] | no_license | #include <iostream>
const int n=3;
struct cb
{
char name[20];
float weight;
int blablabla;
};
using namespace std;
int main() {
cb wow[n];
for (int i = 0; i < n; ++i)
{
cin >> wow[i].name >> wow[i].weight >> wow[i].blablabla;
cout << endl;
}
for (int i = 0; i < n; ++i)
{
cout << wow[i].name << " " << wow[i].weight << " " << wow[i].blablabla << endl;
}
return 0;
}
| true |
a4d61da52b511266031832d083bd39a00867add2 | C++ | mbruening18/CS172-HW06 | /CS172-HW#06/CS172-HW#06/CircleClass.hpp | UTF-8 | 978 | 3.25 | 3 | [] | no_license | //
// CircleClass.hpp
// CS172-HW#06
//
// Created by Megan Bruening on 11/4/16.
// Copyright © 2016 Megan Bruening. All rights reserved.
//
//
#ifndef CircleClass_hpp
#define CircleClass_hpp
#include <stdio.h>
//EX06_04 – Liang Programming Exercise 14.3: The Circle class
//creates a circle class
class Circle
{
//makes private
private:
double radius;
static int numberOfObjects;
//makes public
public:
//no-arg constructor
Circle();
//arg constructor
Circle(double newRadius);
//gets the area, radius, NumberOfObject
double getArea()const;
double getRadius()const;
static int getNumberOfObject();
//sets the radius
void setRadius(double newRadius);
//operator for relational
bool operator<(Circle& c);
bool operator<=(Circle& c);
bool operator==(Circle& c);
bool operator!=(Circle& c);
bool operator>(Circle& c);
bool operator>=(Circle& c);
};
#endif /* CircleClass_hpp */
| true |
38fb4b7d06f2f3b1b5eecf14ac82a62d64c14734 | C++ | moAmaan/Assignments | /11_1.cpp | UTF-8 | 1,849 | 4 | 4 | [] | no_license | #include<iostream>
using namespace std;
class Bank
{
string name;
long int accountn;
double balance;
char type;
double new_balance(double amt)
{
balance+=amt;
return balance;
}
public:
void input()
{
cout<<"enter name of depositer";
cin>>name;
cout<<"enter the account no.";
cin>>accountn;
cout<<"which type of account"<<endl<<"type C for current"<<endl<<"type S for saving account"<<endl;
cin>>type;
}
int deposit()
{
double amt;
cout<<"enter ammount to deposit";
cin>>amt;
cout<<"account balance is :"<<new_balance(amt)<<endl;
}
void withdraw()
{
int amt;
cout<<"enter amount to withdraw:"<<endl;
cin>>amt;
if(balance<=0)
{
cout<<"insufficient balance!!!"<<endl;
}
if(amt>balance)
{
cout<<"balance is low!!!";
}
else
{
balance-=amt;
}
}
void display()
{
cout<<"\n\n ACCOUNT INFO.";
cout<<"NAME:"<<name;
cout<<"ACCOUNT NUMBER:"<<accountn;
cout<<"ACCOUNT TYPE:"<<type;
cout<<"BALANCE OF"<<name<<"is:"<<balance;
}
};
int main()
{
Bank b;
int n;
b.input();
for(int i=0;i<4;i++)
{
cout<<"Features are:\n 1)Deposition\n 2)withdrawal\n 3)Display details"<<endl;
cout<<"enter your choice"<<endl;
cin>>n;
switch (n)
{
case 1:
b.deposit();
break;
case 2:
b.withdraw();
break;
case 3:
b.display();
break;
default :
cout<<"wrong choice";
}
}
return 0;
}
| true |
1af8ddec477b4822478325ae1294a5f0edc638d6 | C++ | toby0zmy/NoahGameFrame | /NFComm/NFKernelPlugin/g3dlite/Include/RegistryUtil.h | UTF-8 | 2,661 | 2.71875 | 3 | [
"Apache-2.0"
] | permissive | /**
@file RegistryUtil.h
@created 2006-04-06
@edited 2006-04-06
Copyright 2000-2006, Morgan McGuire.
All rights reserved.
*/
#ifndef G3D_REGISTRYUTIL_H
#define G3D_REGISTRYUTIL_H
#include "platform.h"
#include "g3dmath.h"
// This file is only used on Windows
#ifdef G3D_WIN32
#include <string>
namespace G3D
{
/**
Provides generalized Windows registry querying.
All key names are one string in the format:
"[base key]\[sub-keys]\value"
[base key] can be any of the following:
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_PERFORMANCE_DATA
HKEY_PERFORMANCE_NLSTEXT
HKEY_PERFORMANCE_TEXT
HKEY_USERS
keyExists() should be used to validate a key before reading or writing
to ensure that a debug assert or false return is for a different error.
*/
class RegistryUtil
{
public:
/** returns true if the key exists */
static bool keyExists(const std::string& key);
/** returns false if the key could not be read for any reason. */
static bool readInt32(const std::string& key, int32& valueData);
/**
Reads an arbitrary amount of data from a binary registry key.
returns false if the key could not be read for any reason.
@beta
@param valueData pointer to the output buffer of sufficient size. Pass NULL as valueData in order to have available data size returned in dataSize.
@param dataSize size of the output buffer. When NULL is passed for valueData, contains the size of available data on successful return.
*/
static bool readBytes(const std::string& key, uint8* valueData, uint32& dataSize);
/** returns false if the key could not be read for any reason. */
static bool readString(const std::string& key, std::string& valueData);
/** returns false if the key could not be written for any reason. */
static bool writeInt32(const std::string& key, int32 valueData);
/**
Writes an arbitrary amount of data to a binary registry key.
returns false if the key could not be written for any reason.
@param valueData pointer to the input buffer
@param dataSize size of the input buffer that should be written
*/
static bool writeBytes(const std::string& key, const uint8* valueData, uint32 dataSize);
/** returns false if the key could not be written for any reason. */
static bool writeString(const std::string& key, const std::string& valueData);
};
} // namespace G3D
#endif // G3D_WIN32
#endif // G3D_REGISTRYTUIL_H | true |
8b43e7b20c1d66805c2cbe216c91be3b8861d5f8 | C++ | SineadOSullivan/gazebo | /Project/behavior/avoidBoundary.cpp | UTF-8 | 2,671 | 2.828125 | 3 | [] | no_license | #include "avoidBoundary.h"
using namespace gazebo;
using namespace std;
AvoidBoundary::AvoidBoundary()
: Behavior(1.0d)
{
}
AvoidBoundary::AvoidBoundary(double kBoundary)
: Behavior(kBoundary)
{
}
math::Vector3 AvoidBoundary::avoidBoundarySubsumption(math::Vector2d minimum, math::Vector2d maximum, math::Vector3 currentPosition)
{
const double boundaryThreshold = 1.0d;
// Check for being within minimum threshold
if ((currentPosition[0] - minimum[0]) < boundaryThreshold)
{
return (math::Vector3(1.0d, 0.0d, 0.0d));
}
else if ((currentPosition[1] - minimum[1]) < boundaryThreshold)
{
return (math::Vector3(0.0d, 1.0d, 0.0d));
}
// Check for being within maximum threshold
else if ((maximum[0] - currentPosition[0]) < boundaryThreshold)
{
return (math::Vector3(-1.0d, 0.0d, 0.0d));
}
else if ((maximum[1] - currentPosition[1]) < boundaryThreshold)
{
return (math::Vector3(0.0d, -1.0d, 0.0d));
}
// Nothing to worry about
else
return math::Vector3(0.0d, 0.0d, 0.0d);
}
void AvoidBoundary::avoidBoundaryDamn(math::Vector3 currentPosition, std::vector< std::vector<double> >& votes, std::vector<double>& R, std::vector<double>& T)
{
// Method Variables
double width = 9.0;
double x = currentPosition[0];
// Loop through Vote matrix
for( unsigned int i = 0; i < R.size(); i++ )
{
for( unsigned int j = 0; j < T.size(); j++ )
{
if( R[i]*cos(T[j]) >= 0.95*width-x || R[i]*cos(M_PI-T[j]) >= x-0.05*width ) // Boundary cross condition
{
votes[i][j] -= this->_kGain;
}
else if( R[i]*cos(T[j]) <= 0.8*width-x || R[i]*cos(M_PI-T[j]) <= x-0.2*width ) // Interior condition
{
votes[i][j] += 0.5;
}
}
}
}
math::Vector3 AvoidBoundary::avoidBoundaryMotorSchema(math::Vector3 currentPosition)
{
/**Assume the boundary is given by a box oriented along the Y axis**/
// Fixed Parameters
const double thresh = 0.25; // threshold fraction
const double width = 9.0; // X-width of the boundary
// Method Variables
double x = currentPosition[0]; // Current X position
math::Vector3 V = math::Vector3(0,0,0);
//Check boundary condition
if( x <= 0 || x >= width )
{
V.Set( -10*_kGain*( x - 0.5*width ), 0, 0 );
}
else if( x < thresh*width )
{
V.Set( _kGain/pow(x-0.05*width,2), 0, 0 );
}
else if( x > (1-thresh)*width )
{
V.Set( -_kGain/pow(x-0.95*width,2), 0, 0 );
}
// Return Result
return V;
}
| true |
9a10fcb34564cfb7bad8e03cce08c7dec4084458 | C++ | sibivel/nrc-sumo-2018 | /move_forward/move_forward.ino | UTF-8 | 3,243 | 2.828125 | 3 | [] | no_license | //TODO: Integrate Gyro
//TODO: STATES!!!!!
// probably need to do something that puts the robot into a state where it will get back to the point that it can move normally before allowing any other movements except for those of higher priority
#define RS A9 // Right Sensor (looking at it from the front with wires going up)
#define LS A8 // Left Sensor
#define NUM_READINGS 10
#define DETECTION_THRESHOLD 350 // mm
#define LARGE_THRESHOLD 600
#define SMALL_THRESHOLD 350
//accelerometer, just use one axis (for now) we dont need to look at all of the axes.
#define ACC_Y A4
#define ACC_UPPER_THRESHOLD 85
#define ACC_LOWER_THRESHOLD 79
#define RIGHT_MOTOR_DIR 12
#define LEFT_MOTOR_DIR 13
#define RIGHT_MOTOR_POWER 3
#define LEFT_MOTOR_POWER 11
#define RIGHT_MOTOR_BRAKE 9
#define LEFT_MOTOR_BRAKE 8
//bumper buttons
#define RIGHT_BUTTON 18
#define BACK_BUTTON 19
#define LEFT_BUTTON 20
//light sensors
#define TOP_RIGHT A12
#define BOTTOM_RIGHT A13
#define BOTTOM_LEFT A14
#define TOP_LEFT A15
#define LIGHT_THRESHOLD 110
volatile bool right_bumper, back_bumper, left_bumper;
// need threshold for pushing and detection
// if difference after detection is within a certain range after detection, then go straight, outside that range but below some other threshold, rotate the robot, if its an incredibly large distance, the sensor is screwy (assuming both values are below detection threshold
void setup() {
//Setup sensors
Serial.begin(9600);
pinMode(RS, INPUT);
pinMode(LS, INPUT);
//Setup Channel A
pinMode(RIGHT_MOTOR_DIR, OUTPUT); //Initiates Motor Channel A pin
pinMode(RIGHT_MOTOR_BRAKE, OUTPUT); //Initiates Brake Channel A pin
//Setup Channel B
pinMode(LEFT_MOTOR_DIR, OUTPUT); //Initiates Motor Channel A pin
pinMode(LEFT_MOTOR_BRAKE, OUTPUT); //Initiates Brake Channel A pin
right_bumper = 0;
back_bumper = 0;
left_bumper = 0;
// attachInterrupt(digitalPinToInterrupt(RIGHT_BUTTON), right_isr, HIGH);
// attachInterrupt(digitalPinToInterrupt(BACK_BUTTON), back_isr, HIGH);
// attachInterrupt(digitalPinToInterrupt(LEFT_BUTTON), left_isr, HIGH);
//
// attachInterrupt(digitalPinToInterrupt(RIGHT_BUTTON), right_isf, LOW);
// attachInterrupt(digitalPinToInterrupt(BACK_BUTTON), back_isf, LOW);
// attachInterrupt(digitalPinToInterrupt(LEFT_BUTTON), left_isf, LOW);
}
void loop(){
leftMotor(255);
rightMotor(255);
Serial.println("fwd");
}
void rightMotor(int power) {
if (power == 0) {
digitalWrite(RIGHT_MOTOR_BRAKE, HIGH);
analogWrite(RIGHT_MOTOR_POWER, 0);
}
else {
digitalWrite(RIGHT_MOTOR_BRAKE, LOW);
if (power < 0) {
digitalWrite(RIGHT_MOTOR_DIR, LOW);
}
else {
digitalWrite(RIGHT_MOTOR_DIR, HIGH);
}
analogWrite(RIGHT_MOTOR_POWER, abs(power));
}
}
void leftMotor(int power) {
if (power == 0) {
digitalWrite(LEFT_MOTOR_BRAKE, HIGH);
analogWrite(LEFT_MOTOR_POWER, 0);
}
else {
digitalWrite(LEFT_MOTOR_BRAKE, LOW);
if (power < 0) {
digitalWrite(LEFT_MOTOR_DIR, LOW);
}
else {
digitalWrite(LEFT_MOTOR_DIR, HIGH);
}
analogWrite(LEFT_MOTOR_POWER, abs(power));
}
}
| true |
cd518e70ea98544b00eed949748132f745dcbf24 | C++ | itsabhijeet/Leetcode-ChallengeSols | /Odd Even Linked List.cpp | UTF-8 | 1,346 | 3.390625 | 3 | [] | no_license | /**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
class Solution {
public:
ListNode* oddEvenList(ListNode* head) {
if(head == NULL) return head;
ListNode* odd=NULL,*oddHead=NULL;
ListNode* even = NULL,*evenHead=NULL;
int i=1;
ListNode* temp = head;
while(temp!=NULL){
ListNode* next = temp->next;
if(i==1){
odd = temp;
oddHead = odd;
}
else if(i==2) {even=temp;
evenHead=temp;
}
else{
if(i&1){
odd->next = temp;
odd = odd->next;
}
else{
even->next = temp;
even = even->next;
}
}
// if(odd!=NULL)
temp=next;;
i++;
}
odd->next = NULL;
if(even!=NULL)
even->next=NULL;
odd->next = evenHead;
return oddHead;
}
}; | true |
771449a758275fb0be2b11b44572a549b6d6233e | C++ | shanesteer/Word-Calculator | /BarChart.h | UTF-8 | 384 | 2.828125 | 3 | [] | no_license | #ifndef BARCHART_H
#define BARCHART_H
using namespace std;
#include <string>
#include <vector>
class BarChart
{
public:
BarChart(vector<string> wordHolding, vector<int> arrayOfWords, float myTotalSize);
void createBarChart();
void printBarChart();
private:
vector<string> wordHolding;
vector<int> arrayOfWords;
float myTotalSize;
};
#endif | true |
85ec162ff61e27d18e19c56c9ea57e22d3202942 | C++ | AHelper/llvm-z80-target | /lib/Support/ErrorHandling.cpp | UTF-8 | 2,515 | 2.546875 | 3 | [
"NCSA",
"Spencer-94",
"BSD-3-Clause"
] | permissive | //===- lib/Support/ErrorHandling.cpp - Callbacks for errors ---------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines an API used to indicate fatal error conditions. Non-fatal
// errors (most of them) should be handled through LLVMContext.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h"
#include "llvm/System/Threading.h"
#include <cassert>
#include <cstdlib>
using namespace llvm;
using namespace std;
static fatal_error_handler_t ErrorHandler = 0;
static void *ErrorHandlerUserData = 0;
void llvm::install_fatal_error_handler(fatal_error_handler_t handler,
void *user_data) {
assert(!llvm_is_multithreaded() &&
"Cannot register error handlers after starting multithreaded mode!\n");
assert(!ErrorHandler && "Error handler already registered!\n");
ErrorHandler = handler;
ErrorHandlerUserData = user_data;
}
void llvm::remove_fatal_error_handler() {
ErrorHandler = 0;
}
void llvm::report_fatal_error(const char *reason) {
report_fatal_error(Twine(reason));
}
void llvm::report_fatal_error(const std::string &reason) {
report_fatal_error(Twine(reason));
}
void llvm::report_fatal_error(const Twine &reason) {
if (!ErrorHandler) {
errs() << "LLVM ERROR: " << reason << "\n";
} else {
ErrorHandler(ErrorHandlerUserData, reason.str());
}
// If we reached here, we are failing ungracefully. Run the interrupt handlers
// to make sure any special cleanups get done, in particular that we remove
// files registered with RemoveFileOnSignal.
sys::RunInterruptHandlers();
exit(1);
}
void llvm::llvm_unreachable_internal(const char *msg, const char *file,
unsigned line) {
// This code intentionally doesn't call the ErrorHandler callback, because
// llvm_unreachable is intended to be used to indicate "impossible"
// situations, and not legitimate runtime errors.
if (msg)
dbgs() << msg << "\n";
dbgs() << "UNREACHABLE executed";
if (file)
dbgs() << " at " << file << ":" << line;
dbgs() << "!\n";
abort();
}
| true |
31ae55cdf73e5157a3e16c33134e41b3d768c19d | C++ | rpgki/Pry1 | /LstAdy.h | UTF-8 | 2,334 | 3.25 | 3 | [] | no_license | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: LstAdy.h
* Author: Carlos
*
* Created on 6 de septiembre de 2016, 11:05 PM
*/
#ifndef LSTORDADY_H
#define LSTORDADY_H
#include <memory>
#include <iostream>
#include <sstream>
using namespace std;
class LstAdy {
// Representa la lista ordenada de adyacencias de un nodo en Grafo.
public:
// Construye una lista de adyacencias vacía.
LstAdy();
// Construye una lista de adyacencias idéntica a orig.
LstAdy(const LstAdy& orig);
// Destruye a *this retornando toda la memoria asignada dinámicamente.
~LstAdy();
// MOD: *this.
// EFE: agrega nady a *this en forma ordenada.
// totAdy() aumenta en uno.
void agr(int nady);
// EFE: retorna true si ady pertenece a *this y false en caso contrario.
bool bus(int ady);
// MOD: *this.
// EFE: si ady pertenece a *this, lo elimina, en caso contrario no tiene efecto.
// si ady pertenece a *this, totAdy() disminuye en uno.
void elm(int ady);
// EFE: retorna una hilera como {2,5,8} que representa las adyacencias en *this.
string aHil();
// EFE: retorna la cantidad de adyacencias guardadas en *this.
int totAdy();
// EFE: retorna un arreglo de enteros que incluye todas las adyacencias en *this.
int* obtAdy();
private:
struct NdoLstAdy { // representa el nodo de una lista de adyacencias
int vrtD; // representa la posición del vértice destino en Grafo
shared_ptr<NdoLstAdy> sgt; // representa el apuntador inteligente al siguiente nodo
NdoLstAdy(): vrtD(0),sgt(nullptr){}; // constructor estándar
NdoLstAdy(int nuevo):vrtD(nuevo),sgt(0){}; //constructor no estándar
~NdoLstAdy(){/*cout << "borrando: " << vrtD << endl;*/}; // destructor
};
int* arrp; //representa el vector con las adyacencias en *this
int cntAdy; // representa la cantidad de adyacencias guardadas en *this.
shared_ptr<NdoLstAdy> inicio; // representa el apuntador al inicio de la lista
};
#endif /* LSTORDADY_H */ | true |
a28bab576de71347e04760aeed7dee71ead9118f | C++ | moevm/oop | /8304/Ryzhickov Alexander/Ryzhickov_Alex_lr7/MyGame/Gamer/Gamer.cpp | UTF-8 | 7,594 | 2.765625 | 3 | [] | no_license | //
// Created by Alex on 01.05.2020.
//
#include <iostream>
#include "Gamer.h"
#include "../Exceptions/UpdateUnitPositionExeption/CellNotFreeException.h"
using namespace Logging;
using namespace MyGameException;
namespace MyGame {
Gamer::Gamer(Field *field, Logger *logger, int xPositionBase, int yPositionBase, GameSaver *gameSaver,
GameLoader *gameLoader, int number, int startMoney) {
Gamer::number = number;
Gamer::field = field;
Gamer::logger = logger;
Gamer::units = new Unit *[10];
Gamer::base = new Base(units, xPositionBase, yPositionBase, 10, field, 100, startMoney);
field->setBase(xPositionBase, yPositionBase, base);
widthField = field->getWidth();
heightField = field->getHeight();
Gamer::gameSaver = gameSaver;
Gamer::gameLoader = gameLoader;
}
Gamer::~Gamer() {
int countUnits = base->getCountUnits();
for (int i = 0; i < countUnits; ++i) {
bool is = true;
for (int num : base->vectorDeleteUnits) {
if (i == num) {
is = false;
break;
}
}
if (is) {
delete (units[i]);
}
}
delete (units);
delete (base);
}
void Gamer::addSwordsmen(int x, int y) {
try {
if (x >= 0 && x < widthField && y >= 0 && y < heightField) {
base->addSwordsmen(x, y);
logger->logAddSwordsmen(x, y);
} else {
std::cout << "x or y is incorrect !\n";
}
} catch (CellNotFreeException &ex) {
std::cout << "Exception in addUnit method\n";
std::cout << ex.what();
}
}
void Gamer::addSpearmen(int x, int y) {
try {
if (x >= 0 && x < widthField && y >= 0 && y < heightField) {
base->addSpearmen(x, y);
logger->logAddSpearmen(x, y);
} else {
std::cout << "x or y is incorrect !\n";
}
} catch (CellNotFreeException &ex) {
std::cout << "Exception in addUnit method\n";
std::cout << ex.what();
}
}
void Gamer::addArcher(int x, int y) {
try {
if (x >= 0 && x < widthField && y >= 0 && y < heightField) {
base->addArcher(x, y);
logger->logAddArcher(x, y);
} else {
std::cout << "x or y is incorrect !\n";
}
} catch (CellNotFreeException &ex) {
std::cout << "Exception in addUnit method\n";
std::cout << ex.what();
}
}
void Gamer::addMagician(int x, int y) {
try {
if (x >= 0 && x < widthField && y >= 0 && y < heightField) {
base->addMagician(x, y);
logger->logAddMagician(x, y);
} else {
std::cout << "x or y is incorrect !\n";
}
} catch (CellNotFreeException &ex) {
std::cout << "Exception in addUnit method\n";
std::cout << ex.what();
}
}
void Gamer::addKing(int x, int y) {
try {
if (x >= 0 && x < widthField && y >= 0 && y < heightField) {
base->addKing(x, y);
logger->logAddKing(x, y);
} else {
std::cout << "x or y is incorrect !\n";
}
} catch (CellNotFreeException &ex) {
std::cout << "Exception in addUnit method\n";
std::cout << ex.what();
}
}
void Gamer::addKnight(int x, int y) {
try {
if (x >= 0 && x < widthField && y >= 0 && y < heightField) {
base->addKnight(x, y);
logger->logAddKnight(x, y);
} else {
std::cout << "x or y is incorrect !\n";
}
} catch (CellNotFreeException &ex) {
std::cout << "Exception in addUnit method\n";
std::cout << ex.what();
}
}
void Gamer::loadGamerState() {
prepareForLoad();
int count;
gameLoader->loadCountUnits(&count);
int numberInArray;
std::string type;
int x;
int y;
int health;
int maxHealth;
int armor;
int maxArmor;
int damage;
int attackBonus;
for (int i = 0; i < count; ++i) {
gameLoader->loadUnitsFromFile(&numberInArray, &type, &x, &y, &health, &maxHealth, &armor, &maxArmor,
&damage, &attackBonus);
logger->logLoadUnit(x, y, type, health, maxHealth, armor, maxArmor, damage, attackBonus);
if (type == "Archer") {
base->loadArcher(x, y, i, health, armor, damage, attackBonus);
} else if (type == "Magician") {
base->loadArcher(x, y, i, health, armor, damage, attackBonus);
} else if (type == "King") {
base->loadKing(x, y, i, health, armor, damage, attackBonus);
} else if (type == "Knight") {
base->loadKnight(x, y, i, health, armor, damage, attackBonus);
} else if (type == "Swordsmen") {
base->loadSworsmen(x, y, i, health, armor, damage, attackBonus);
} else if (type == "Spearmen") {
base->loadSpearmen(x, y, i, health, armor, damage, attackBonus);
}
}
}
void Gamer::saveGamerState() {
gameSaver->printInSaveFile("Gamer " + std::to_string(number) + '\n');
gameSaver->printInSaveFile(base->getInformationAboutBase());
gameSaver->printInSaveFile(getInfromationAboutUnitsForSave());
}
std::string Gamer::getInfromationAboutUnitsForSave() {
std::string informationAboutUnits;
informationAboutUnits.append("CountUits " + std::to_string(base->getCountUnitsInGame()) + "\n\n");
int b = base->getCountUnits();
for (int i = 0; i < b; ++i) {
bool is = true;
for (int num : base->vectorDeleteUnits) {
if (i == num) {
is = false;
break;
}
}
if (is) {
informationAboutUnits.append(units[i]->getInformationAboutUnit());
}
}
return informationAboutUnits;
}
int Gamer::getInformationAboutMoney() {
return base->getMoney();
}
int Gamer::getInformationAboutBaseHealth() {
return base->getHealthBase();
}
void Gamer::prepareForLoad() {
int b = base->getCountUnits();
for (int i = 0; i < b; ++i) {
bool is = true;
for (int num : base->vectorDeleteUnits) {
if (i == num) {
is = false;
break;
}
}
if (is) {
delete (units[i]);
}
}
delete (units);
delete (base);
Gamer::units = new Unit *[10];
int xPositionBase;
int yPositionBase;
int countMaxUnits;
int health;
int money;
gameLoader->loadBaseFromFile(&xPositionBase, &yPositionBase, &countMaxUnits, &health, &money);
Gamer::base = new Base(units, xPositionBase, yPositionBase, 10, field, health, money);
field->setBase(xPositionBase, yPositionBase, base);
}
int *Gamer::getMoneyAdress() {
return base->getMoneyAdresse();
}
} | true |
a51b3c9e01d27acaa63738c7bc32247a74dc3e19 | C++ | StevensDeptECE/CPE390 | /old/2021S/02c++fundamentals/02loops.cc | UTF-8 | 848 | 3.5 | 4 | [] | no_license | #include <iostream>
namespace stevens {
int x; // global variables are initialized to zero by default
};
// 1 + 2 + 3 + 4 + .... + 100
// 100 + 99 + 98 + ... + 1
// n(n+1)/2
void f() {
int xxx =2;
int yyy =2;
int sum; // not variables on the stack (in a function!)
// i are a good programmer
for (int i = 1; i <= 100; i++)
sum = sum + i;
std::cout << "sum=" << sum << '\n';
}
// 1 + 2 + 3 + ... + n
int sum(int n) {
int total = 0;
for (int i=1; i <= n; i++)
{
total += i; // total = total + i;
}
return total;
}
// product of the numbers 1 *2 * 3 * ... *n
int fact(int n) {
int ans = 1;
for (int i = n; i > 0; i--){
ans = ans * i;
}
return ans;
}//well this is more fun
int main() {
for (int i = 1; i <= 10; i++)
std::cout << i;
//int a = 9000;
//int b = 20;
//int c[100];
f();
}
| true |
423b6a41056fade893f3e8f4f0f62c43ea823452 | C++ | apopovicius/pg | /cpp/small_stuff/naive.cpp | UTF-8 | 891 | 3.421875 | 3 | [] | no_license | #include <iostream>
class Animal {
public:
virtual void speak() = 0;
};
class Cat: public Animal {
CatSpeakBehaviour behaviour = new CatSpeakBehaviour();
public void speak() ovveride{
std::cout << behavior.Speak();
}
};
class Dog: public Animal {
DogSpeakBehaviour behaviour = new DogSpeakBehaviour();
public void speak() ovveride{
return behavior.Speak();
}
};
class ISpeakBehaviour {
public:
virtual void Speak();
};
class CatSpeakBehaviour: public ISpeakBehaviour {
public:
std::string Speak() {
return "mjau";
}
}
class DogSpeakBehaviour: public ISpeakBehaviour {
public:
std::string Speak() {
return "woof";
}
}
int main() {
Animal dog = new Dog();
dog.speak();
Animal cat = new Cat();
cat.speak();
//Dog - Woof
//Cat - Meow
return 0;
} | true |
b17bf23405087012a4c2c61c272aab48f8c0d9b7 | C++ | tejasborkar74/Recursion-codes | /Sort an array using recursion.cpp | UTF-8 | 887 | 3.015625 | 3 | [] | no_license | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
// Sort array using Recursion
void shiftarray(vector<int> &arr,int idx,int last)
{
int temp = arr[last];
for(int i=last-1;i>=idx;i--)
{
arr[i+1] = arr[i];
}
arr[idx] = temp;
}
void sort_recursion(vector<int> &arr,int i)
{
if(i==0)return ;
if(i==1 && arr[0]>arr[1])
{
swap(arr[0],arr[1]);
return;
}
sort_recursion(arr,i-1);
for(int j=0;j<i;j++)
{
if(arr[j] > arr[i])
{
shiftarray(arr,j,i);
}
}
return;
}
int main()
{
int n;cin>>n;
vector<int> arr(n);
for(int i=0;i<n;i++)cin>>arr[i];
sort_recursion(arr,n-1);
for(int i : arr)cout<<i<<" ";
}
| true |
62a646e9a9f3ebf6712baec63f6c153f3b13fb15 | C++ | Al7ech/ProblemSolving | /algospot/src/canadatrip.cpp | UTF-8 | 1,108 | 2.90625 | 3 | [] | no_license | #include <stdio.h>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;
typedef struct City
{
int L,M,G;
}city;
int T;
int N,K;
vector<city> D;
ll count(int x)
{
ll ret = 0;
for(city C: D)
{
if(x<C.L-C.M)
ret += 0;
else if(x<C.L)
ret += (x-(C.L-C.M))/C.G + 1;
else
ret += C.M/C.G + 1;
}
return ret;
}
int main()
{
scanf("%d",&T);
for(int t=0;t<T;t++)
{
scanf("%d %d",&N,&K);
D.clear();
int max_x = -1;
for(int i=0;i<N;i++)
{
city X;
scanf("%d %d %d",&X.L,&X.M,&X.G);
D.push_back(X);
max_x = max(max_x,X.L);
}
int min_x = 0;
while(min_x < max_x)
{
int mid_x = (min_x + max_x) / 2;
if(count(mid_x) >= (ll)K) max_x = mid_x;
else min_x = mid_x + 1;
}
printf("%d\n",min_x);
}
return 0;
} | true |
9501dd3edf2d288cf2f8f9aa0a0551ecec0881b8 | C++ | Alfeim/njuee_LeetCode_Solutions | /Cpp/Submit Records/705. Design HashSet.cpp | UTF-8 | 952 | 3.46875 | 3 | [] | no_license | /********************************************
作者:Alfeim
题目:设计哈希集合
时间消耗:128ms
解题思路:最直接的散列表的生成方式,即哈希函数为 键值%(大于最大值的最接近的一个素数)
********************************************/
class MyHashSet {
public:
/** Initialize your data structure here. */
MyHashSet():hash_container(1000007,0){
}
void add(int key) {
hash_container[key % 1000007] = 1;
}
void remove(int key) {
hash_container[key % 1000007] = 0;
}
/** Returns true if this set contains the specified element */
bool contains(int key) {
return hash_container[key % 1000007] == 1;
}
vector<int> hash_container;
};
/**
* Your MyHashSet object will be instantiated and called as such:
* MyHashSet* obj = new MyHashSet();
* obj->add(key);
* obj->remove(key);
* bool param_3 = obj->contains(key);
*/
| true |
10d9374ca7b6f73af2077e81de437a5c2a891dbd | C++ | ancutahij/CarStore | /CarStore/RepositoryTests.cpp | UTF-8 | 1,773 | 3.28125 | 3 | [] | no_license | #include"Tests.h"
void Test::addTests()
{
Repository repo;
Car car1{ "223","Toyota","x345", "family" };
Car car2{ "245", "Audi", "24", "trip" };
assert(repo.getSize() == 0);
repo.addNewElement(car1);
assert(repo.getSize() == 1);
repo.addNewElement(car2);
assert(repo.getSize() == 2);
bool exceptionThrown = false;
try
{
repo.addNewElement(car1);
}
catch (RepositoryException &exception)
{
exceptionThrown = true;
std::cout << exception.what();
}
assert(exceptionThrown);
}
void Test::deleteTests()
{
Repository repo;
Car car1{ "223","Toyota","x345", "family" };
Car car2{ "245", "Audi", "24", "trip" };
Car car3{ "fe2","Opel", "3446", "family" };
repo.addNewElement(car1);
repo.addNewElement(car2);
repo.addNewElement(car3);
assert(repo.getSize() == 3);
repo.deleteElement("245");
assert(repo.getSize() == 2);
Car car = repo.getElement(1);
assert(car.getRegistration() == "fe2");
assert(car.getModel() == "3446");
assert(car.getManufacturer() == "Opel");
assert(car1.getType() == "family");
}
void Test::updateTests()
{
Repository repo;
Car car1{ "223","Toyota","x345", "family" };
Car car2{ "245", "Audi", "24", "trip" };
Car car3{ "fe2","Opel", "3446", "family" };
repo.addNewElement(car1);
repo.addNewElement(car2);
repo.addNewElement(car3);
Car car = repo.getElement(1);
std::string manufacturer = "Mercedes";
repo.updateElement("245", "Mercedes", &Car::setManufacturer);
}
void Test::copyConstructer()
{
Repository repo;
Car car1{ "223","Toyota","x345", "family" };
Car car2{ "245", "Audi", "24", "trip" };
Car car3{ "fe2","Opel", "3446", "family" };
repo.addNewElement(car1);
repo.addNewElement(car2);
repo.addNewElement(car3);
Repository newRepo{ repo };
assert(newRepo.getSize() == 3);
} | true |
75d711b1fb3ba0cca289f2113f279c3e08851de1 | C++ | csalles/maratona | /1489_old.cpp | UTF-8 | 4,397 | 2.8125 | 3 | [] | no_license | #include <vector>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
using namespace std;
const int INF = 1000000;
struct Edge {
int u, v, w;
Edge(int u, int v, int w) : u(u), v(v), w(w) {}
// order edges by weight
bool operator <(const Edge& x) const {
return w < x.w;
}
};
int edmonds(vector<Edge>& edgeList, int V, int R) {
// determine min cost of edge entering each vertex
vector<Edge> minInEdge(V, Edge(-1, -1, INF));
for (int i=0; i<edgeList.size(); i++) {
Edge e = edgeList[i];
minInEdge[e.v] = min(minInEdge[e.v], e);
}
minInEdge[R] = Edge(-1, R, 0);
// assign vertices to their cyclic group
vector<int> group(V, 0);
vector<bool> visited(V, false), isCycleGroup(V, false);
int cnt = 0;
for (int i = 0; i < V; i++) {
if (visited[i])
continue;
int node = i; vector<int> path;
while (node != -1 && !visited[node]) {
visited[node] = true;
path.push_back(node);
node = minInEdge[node].u;
}
bool isCycle = false;
for (int j=0; j<path.size(); j++) {
int v = path[j];
group[v] = cnt;
if (v == node)
isCycleGroup[cnt] = isCycle = true;
if (!isCycle)
cnt++;
}
if (isCycle)
cnt++;
}
// when there are no cycles
if (cnt == V) {
int result = 0;
for (int j=0; j<minInEdge.size(); j++) {
Edge e = minInEdge[j];
result += e.w;
}
return result;
}
int result = 0;
for (int j=0; j<minInEdge.size(); j++) {
Edge e = minInEdge[j];
if (isCycleGroup[group[e.v]])
result += e.w;
}
// form new graph with groups
vector<Edge> n_edgeList;
for (int j=0; j<edgeList.size(); j++) {
Edge e = edgeList[j];
int u = group[e.u], v = group[e.v], w = e.w;
if (u == v)
continue;
else if (isCycleGroup[v])
n_edgeList.push_back(Edge(u, v, w - minInEdge[e.v].w));
else
n_edgeList.push_back(Edge(u, v, w));
}
return result + edmonds(n_edgeList, cnt, group[R]);
}
int main() {
int k, K;
cin >> K;
for(int k=1; k<=K; k++) {
int n;
cin >> n;
vector<Edge> edgeList;
//if(k==198) cout << "# " << n << endl;
bool mat[101][101];
for(int u=0; u<101; u++)
for(int v=0; v<101; v++)
mat[u][v] = false;
bool dgZero = false;
vector<int> dg(200);
for(int u=0; u<n; u++) {
cin >> dg[u];
//if(k==198) cout << "# grau de " << u << " = " << dg[u] << endl;
if(dg[u]==0) dgZero = true;
for(int i=0; i<dg[u]; i++) {
int v;
cin >> v;
v--;
//if(k==191) cout << "# edge " << u << " para " << v << endl;
mat[u][v] = true;
if(mat[u][v]&&mat[v][u]) {
edgeList.push_back( Edge(u,v,1) );
edgeList.push_back( Edge(v,u,1) );
}
//mat[u][v] = true;
}
}
/*
bool simetrico = true;
for(int u=0; u<n && simetrico; u++)
for(int v=0; v<n && simetrico; v++)
if(mat[u][v]!=mat[v][u])
simetrico = false;
*/
//if(!simetrico) result = -10;
//else
bool pairProg = false;
if(n>2 && dgZero==false) {
//pairProg = edmonds(edgeList, n, 0)==n-1;
for(int vv=0; vv<n; vv++) {
if(edmonds(edgeList, n, vv)==n-1) {
pairProg = true;
break;
}
}
}
/*
for(int u=0; u<n; u++) {
vector<Edge> cp = edgeList;
if(edmonds(cp, n, u)==n-1) {
pairProg=true;
break;
}
}
*/
if(n==2||n==0) pairProg=true;
if(n==18&&k>100) pairProg = !pairProg;
if(n==10&&k>197) pairProg = !pairProg;
cout << "Instancia " << k << endl;
if(pairProg) cout << "pair programming" << endl;
else cout << "extreme programming" << endl;
cout << endl;
}
}
| true |
3939ec2c96a1b72520017fbb695b657ffacca568 | C++ | Karmiska/Darkness | /darkness-shared/include/ecs/ComponentData.h | UTF-8 | 1,799 | 2.921875 | 3 | [] | no_license | #pragma once
#include "containers/vector.h"
#include "ComponentTypeStorage.h"
#include "Entity.h"
#include <stack>
namespace ecs
{
constexpr size_t PreferredChunkSizeBytes = 16 * 1024;
class Chunk
{
public:
Chunk(ComponentArcheTypeId archeType)
: m_used{ 0 }
{
auto typeIds = ArcheTypeStorage::instance().typeSetFromArcheTypeId(archeType);
uint32_t combinedTypeBytes = 0;
for (auto&& type : typeIds)
{
auto typeInfo = ComponentTypeStorage::typeInfo(type);
combinedTypeBytes += typeInfo.typeSizeBytes;
}
combinedTypeBytes += sizeof(Entity);
m_elements = PreferredChunkSizeBytes / combinedTypeBytes;
for (auto&& type : typeIds)
{
auto typeInfo = ComponentTypeStorage::typeInfo(type);
m_componentData.emplace_back(typeInfo.create(m_elements));
}
for (int i = 0; i < m_elements; ++i)
m_free.push(i);
}
size_t size() const
{
return m_used;
}
size_t capacity() const
{
return m_elements;
}
size_t available() const
{
return capacity() - size();
}
EntityId allocate()
{
auto id = m_free.top();
m_free.pop();
++m_used;
return id;
}
void free(EntityId id)
{
m_free.push(entityIndexFromEntityId(id));
--m_used;
}
private:
size_t m_elements;
engine::vector<ComponentDataBase*> m_componentData;
std::stack<uint16_t> m_free;
size_t m_used;
};
}
| true |
31e380252d6bfb5908ebbecb393d5475f2d38934 | C++ | annie-anna/ve280-codes | /project2/p2.cpp | UTF-8 | 7,946 | 3.4375 | 3 | [] | no_license | #include<iostream>
#include<cstdlib>
#include "p2.h"
using namespace std;
static bool odd(int num);
// EFFECTS: Returns true is num is odd, returns false otherwise.
static list_t unique_helper(list_t list);
// EFFECTS: Returns a new list comprising of each unique element
// in "list". The order is determined by the last
// occurrence of each unique element in "list".
static list_t reserve_list_n(list_t list, int n);
// EFFECTS£ºReturns a new list consisting of the first n elements in list.
static list_t delete_list_n(list_t list, int n);
// EFFECTS: Returns a new list that deletes the first n elements in list.
static int max(int a, int b);
// EFFECTS: Returns the maximum of a and b.
static bool tree_hasMonotonicPath_helper(tree_t tree, bool(*fn)(int,int));
// EFFECTS: Returns true if there exists a monotonic path in left
// subtree or right subtree.
static bool increase(int a, int b);
// EFFECTS: Returns true if a<=b.
static bool decrease(int a, int b);
// EFFECTS£ºReturns true is a>=b.
static bool contained_by_helper(tree_t A, tree_t B, tree_t(*fn)(tree_t));
// EFFECTS: Returns true if A is contained by B.
int size(list_t list) {
if (list_isEmpty(list)) return 0;
return (1 + size(list_rest(list)));
}
bool memberOf(list_t list, int val) {
if (list_isEmpty(list))return false;
if (list_first(list) == val) return true;
return memberOf(list_rest(list), val);
}
int dot(list_t v1, list_t v2) {
if (size(v1) == 1 || size(v2) == 1) return list_first(v1)*list_first(v2);
return (list_first(v1)*list_first(v2) + dot(list_rest(v1), list_rest(v2)));
}
bool isIncreasing(list_t v) {
if (size(v) == 0 || size(v) == 1) return true;
if (list_first(v) <= list_first(list_rest(v))) return isIncreasing(list_rest(v));
return false;
}
list_t reverse(list_t list) {
if (size(list) == 0) return list;
return append(reverse(list_rest(list)), list_make(list_first(list), list_make()));
}
list_t append(list_t first, list_t second) {
if (list_isEmpty(first)) return second;
return list_make(list_first(first), append(list_rest(first), second));
}
bool isArithmeticSequence(list_t v) {
int vsize = size(v);
if (vsize == 0 || vsize == 1 || vsize == 2) return true;
if (list_first(v) + list_first(list_rest(list_rest(v))) == 2 * list_first(list_rest(v)))
return isArithmeticSequence(list_rest(v));
return false;
}
list_t filter_odd(list_t list) {
return filter(list, odd);
}
static bool odd(int num){
if (num % 2 != 0) return true;
return false;
}
list_t filter(list_t list, bool(*fn)(int)) {
if (list_isEmpty(list))return list;
if (fn(list_first(list)))
return list_make(list_first(list), filter(list_rest(list),fn));
return filter(list_rest(list), fn);
}
list_t unique(list_t list) {
return unique_helper(reverse(list));
}
static list_t unique_helper(list_t list) {
if (size(list) == 0 || size(list) == 1)return list;
list_t unique_list = unique_helper(list_rest(list));
int first = list_first(list);
if (memberOf(unique_list, first))
return unique_list;
return append(unique_list,list_make(first,list_make()));
}
list_t insert_list(list_t first, list_t second, unsigned int n) {
list_t v1 = reserve_list_n(first, n);
list_t v2 = delete_list_n(first, n);
return append(append(v1, second), v2);
}
static list_t reserve_list_n(list_t list, int n) {
if (n == size(list))return list;
if (n == 0) return list_make();
return list_make(list_first(list), reserve_list_n(list_rest(list), n - 1));
}
static list_t delete_list_n(list_t list, int n) {
if (n == size(list)) return list_make();
if (n == 0) return list;
return delete_list_n(list_rest(list), n - 1);
}
list_t chop(list_t list, unsigned int n) {
return reserve_list_n(list, size(list) - n);
}
int tree_sum(tree_t tree) {
if (tree_isEmpty(tree)) return 0;
return tree_elt(tree) + tree_sum(tree_left(tree)) + tree_sum(tree_right(tree));
}
bool tree_search(tree_t tree, int val) {
if (tree_isEmpty(tree)) return false;
if (val == tree_elt(tree)) return true;
return (tree_search(tree_left(tree), val) || tree_search(tree_right(tree), val));
}
int depth(tree_t tree) {
if (tree_isEmpty(tree)) return 0;
return(max(depth(tree_left(tree)), depth(tree_right(tree)))+1);
}
static int max(int a, int b) {
if (a >= b) return a;
return b;
}
int tree_max(tree_t tree) {
int elt = tree_elt(tree);
if (depth(tree) == 1)return tree_elt(tree);
tree_t left = tree_left(tree);
tree_t right = tree_right(tree);
if (!tree_isEmpty(left)) {
if(!tree_isEmpty(right))
return max(elt, max(tree_max(left), tree_max(right)));
else return max(elt, tree_max(left));
}
else return max(elt, tree_max(right));
}
list_t traversal(tree_t tree) {
if (tree_isEmpty(tree)) return list_make();
list_t list_top = list_make(tree_elt(tree), list_make());
list_t temp = append(traversal(tree_left(tree)), list_top);
return append(temp, traversal(tree_right(tree)));
}
bool tree_hasMonotonicPath(tree_t tree) {
return (tree_hasMonotonicPath_helper(tree, increase) || tree_hasMonotonicPath_helper(tree, decrease));
}
static bool tree_hasMonotonicPath_helper(tree_t tree, bool(*fn)(int,int)) {
if (tree_isEmpty(tree))return false;
if (depth(tree) == 1)return true;
tree_t left = tree_left(tree);
tree_t right = tree_right(tree);
int ans1=0, ans2=0;
int elt = tree_elt(tree);
if (!tree_isEmpty(left)) {
if (fn(elt,tree_elt(left))) ans1 = tree_hasMonotonicPath_helper(left,fn);
}
if (ans1) return true;
if(!tree_isEmpty(right)) {
if (fn(elt,tree_elt(right))) ans2 = tree_hasMonotonicPath_helper(right,fn);
}
if (ans2) return true;
else return false;
}
static bool increase(int a, int b) {
if (a <= b) return true;
else return false;
}
static bool decrease(int a, int b) {
if (a >= b) return true;
else return false;
}
bool tree_allPathSumGreater(tree_t tree, int sum) {
int elt = tree_elt(tree);
if (depth(tree) == 1) {
if (elt > sum) return true;
return false;
}
tree_t left=tree_left(tree);
tree_t right = tree_right(tree);
if (!tree_isEmpty(left)) {
if (!tree_isEmpty(right)) {
if (tree_allPathSumGreater(left, sum - elt)&& tree_allPathSumGreater(right, sum - elt))
return true;
else return false;
}
else {
if (tree_allPathSumGreater(left, sum - elt)) return true;
else return false;
}
}
else {
if (tree_allPathSumGreater(right, sum - elt)) return true;
else return false;
}
}
bool covered_by(tree_t A, tree_t B) {
if (tree_isEmpty(A)) return true;
if (tree_isEmpty(B)) {
if (tree_isEmpty(A)) return true;
return false;
}
if (tree_elt(A)== tree_elt(B)) {
return (covered_by(tree_left(A), tree_left(B)) && covered_by(tree_right(A), tree_right(B)));
}
else return false;
}
bool contained_by(tree_t A, tree_t B) {
return(contained_by_helper(A, B, tree_left) || contained_by_helper(A, B, tree_right));
}
static bool contained_by_helper(tree_t A, tree_t B, tree_t (*fn)(tree_t)) {
if (covered_by(A, B)) return true;
if (tree_isEmpty(B))return false;
B = fn(B);
if (contained_by_helper(A, B, tree_left) || contained_by_helper(A, B, tree_right))
return true;
return false;
}
tree_t insert_tree(int elt, tree_t tree) {
tree_t empty_tree = tree_make();
if (tree_isEmpty(tree))
return tree_make(elt, empty_tree, empty_tree);
tree_t left = tree_left(tree);
tree_t right = tree_right(tree);
int top_elt = tree_elt(tree);
if (depth(tree) == 1) {
if (elt < top_elt)
return tree_make(top_elt, tree_make(elt, empty_tree, empty_tree), right);
else return tree_make(top_elt, left, tree_make(elt, empty_tree, empty_tree));
}
if (elt < top_elt)
return tree_make(top_elt,insert_tree(elt, left),right);
else return tree_make(top_elt,left,insert_tree(elt, right));
}
| true |
51d5a32165be2799c1cea4e6f4d4db473e355df9 | C++ | Cemetry/Problem_Solving | /Newton_Interpolation/main.cpp | UTF-8 | 795 | 3.21875 | 3 | [] | no_license | /*
**Author:Tanim Ahmed Bijoy
Kuet,khulna,Bangladesh
***Newton_interpolation.cpp
**/
#include<iostream>
using namespace std;
int main()
{
int n,n1,i,j;
float x[100],f[100],point,sum=0,mult;
cout<<"Enter the number of data?"<<endl;
cin>>n;
cout<<"Enter the corresponding value of x and f(x)"<<endl;
for(int i=0;i<n;i++)
cin>>x[i]>>f[i];
cout<<"Enter the point for calculation"<<endl;
cin>>point;
for(j=0;j<n-1;j++)
{
for(i=n-1;i>j;i--)
f[i]=(f[i]-f[i-1])/(x[i]-x[i-j-1]);
}
for(i=n-1;i>=0;i--)
{
mult=1;
for( j=0;j<i;j++)
mult*=(point-x[j]);
mult*=f[j];
sum+=mult;
}
cout<<"The solution for the given value is"<<sum<<endl;
return 0;
}
| true |
282c0a9d2ad1120581244a22010ff025e73b5310 | C++ | BrianSzuter/CppFundamentals | /ArrayAndStringManipTests/TimeConversionTests.cpp | UTF-8 | 2,390 | 3.09375 | 3 | [] | no_license | #include "stdafx.h"
#include "CppUnitTest.h"
#include "TimeConversion.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace std;
using namespace ArrayAndStringManip;
namespace ArrayAndStringManipTests
{
TEST_CLASS(TimeConversionTests)
{
public:
TEST_METHOD(ToMilitaryTime_12AM)
{
string result = ToMilitaryTime("12:00:00AM");
Assert::AreEqual("00:00:00"s, result);
}
TEST_METHOD(ToMilitaryTime_1AM)
{
string result = ToMilitaryTime("01:00:00AM");
Assert::AreEqual("01:00:00"s, result);
}
TEST_METHOD(ToMilitaryTime_11AM)
{
string result = ToMilitaryTime("11:00:00AM");
Assert::AreEqual("11:00:00"s, result);
}
TEST_METHOD(ToMilitaryTime_12PM)
{
string result = ToMilitaryTime("12:00:00PM");
Assert::AreEqual("12:00:00"s, result);
}
TEST_METHOD(ToMilitaryTime_1PM)
{
string result = ToMilitaryTime("01:00:00PM");
Assert::AreEqual("13:00:00"s, result);
}
TEST_METHOD(ToMilitaryTime_11PM)
{
string result = ToMilitaryTime("11:00:00PM");
Assert::AreEqual("23:00:00"s, result);
}
TEST_METHOD(ToMilitaryTime_ShortHours)
{
string result = ToMilitaryTime("1:00:00PM");
Assert::AreEqual("13:00:00"s, result);
}
TEST_METHOD(ToMilitaryTime_ShortMinutes)
{
string result = ToMilitaryTime("01:0:00PM");
Assert::AreEqual("13:00:00"s, result);
}
TEST_METHOD(ToMilitaryTime_ShortSeconds)
{
string result = ToMilitaryTime("01:00:0PM");
Assert::AreEqual("13:00:00"s, result);
}
TEST_METHOD(ToMilitaryTime_MissingAMPM_ThrowsException)
{
auto func = []() {ToMilitaryTime("01:00:00"); };
Assert::ExpectException<invalid_argument>(func);
}
TEST_METHOD(ToMilitaryTime_MissingHours_ThrowsException)
{
auto func = []() {ToMilitaryTime(":01:00PM"); };
Assert::ExpectException<invalid_argument>(func);
}
TEST_METHOD(ToMilitaryTime_MissingMinutes_ThrowsException)
{
auto func = []() {ToMilitaryTime("01:00PM"); };
Assert::ExpectException<invalid_argument>(func);
}
TEST_METHOD(ToMilitaryTime_MissingMinutes2_ThrowsException)
{
auto func = []() {ToMilitaryTime("01::00PM"); };
Assert::ExpectException<invalid_argument>(func);
}
TEST_METHOD(ToMilitaryTime_MissingSeconds_ThrowsException)
{
auto func = []() {ToMilitaryTime("01:00:PM"); };
Assert::ExpectException<invalid_argument>(func);
}
};
} | true |
42355b4099e55522428f7b594acbaf9f4db72069 | C++ | enneking/raptor_engine | /slot.inl | UTF-8 | 802 | 2.765625 | 3 | [] | no_license |
template<class TListener, class ... FuncArgs>
Slot<TListener, FuncArgs...>::Slot(TListener* const obj, void(TListener::* const func)(FuncArgs...)) : obj_(obj), func_(func)
{
}
template<class TListener, class ... FuncArgs>
void Slot<TListener, FuncArgs...>::Process(FuncArgs... args)
{
(obj_->*func_)(args...);
}
template<class TListener, class ... FuncArgs>
void Slot<TListener, FuncArgs...>::SetId(uint8_t id)
{
id_ = id;
}
template<class TListener, class ... FuncArgs>
uint8_t Slot<TListener, FuncArgs...>::GetId()
{
return id_;
}
template<class TListener, class ... FuncArgs>
void Slot<TListener, FuncArgs...>::SetPriority(uint8_t priority)
{
priority_ = priority;
}
template<class TListener, class ... FuncArgs>
uint8_t Slot<TListener, FuncArgs...>::GetPriority()
{
return priority_;
} | true |
5c1226910cadc14d279273ca34ea193f2427e2fe | C++ | mineawesomeman/JankMonopoly | /src/Board.cpp | UTF-8 | 2,404 | 2.796875 | 3 | [] | no_license | /*
* Board.cpp
*
* Created on: Mar 18, 2021
* Author: daraw
*/
#include "Board.h"
#include <iostream>
#include "Definitions.h"
Board::Board() {
// TODO Auto-generated constructor stub
spacesP = (Space**)malloc(sizeof(Space*) * 32);
*(spacesP+0) = new Space(GO,0,(char*)"GO");
*(spacesP+1) = new Space(STREET,1,(char*)"Irving Ave");
*(spacesP+2) = new Space(CHANCE,2,(char*)"Chance");
*(spacesP+3) = new Space(STREET,3,(char*)"Dover Street");
*(spacesP+4) = new Space(STREET,4,(char*)"Orientle Ave");
*(spacesP+5) = new Space(RAILROAD,5,(char*)"Dallas Station");
*(spacesP+6) = new Space(STREET,6,(char*)"Liverpool Rd");
*(spacesP+7) = new Space(STREET,7,(char*)"Irdell Ave");
*(spacesP+8) = new Space(FREE,8,(char*)"Free");
*(spacesP+9) = new Space(STREET,9,(char*)"Kiley Court");
*(spacesP+10) = new Space(CHANCE,10,(char*)"Chance");
*(spacesP+11) = new Space(STREET,11,(char*)"Enrique Drive");
*(spacesP+12) = new Space(STREET,12,(char*)"Mangrove Lane");
*(spacesP+13) = new Space(RAILROAD,13,(char*)"Illinois Station");
*(spacesP+14) = new Space(STREET,14,(char*)"Annadale Terrace");
*(spacesP+15) = new Space(STREET,15,(char*)"Sandhill Court");
*(spacesP+16) = new Space(FREE,16,(char*)"Free");
*(spacesP+17) = new Space(STREET,17,(char*)"Scotch Pine Way");
*(spacesP+18) = new Space(CHANCE,18,(char*)"Chance");
*(spacesP+19) = new Space(STREET,19,(char*)"Iron Wood Lane");
*(spacesP+20) = new Space(STREET,20,(char*)"Violet Court");
*(spacesP+21) = new Space(RAILROAD,21,(char*)"California Station");
*(spacesP+22) = new Space(STREET,22,(char*)"Evans Way");
*(spacesP+23) = new Space(STREET,23,(char*)"Bosie Run");
*(spacesP+24) = new Space(FREE,24,(char*)"Free");
*(spacesP+25) = new Space(STREET,25,(char*)"O'Brien Place");
*(spacesP+26) = new Space(CHANCE,26,(char*)"Chance");
*(spacesP+27) = new Space(STREET,27,(char*)"Old Camp Road");
*(spacesP+28) = new Space(STREET,28,(char*)"Baker Way");
*(spacesP+29) = new Space(RAILROAD,29,(char*)"Kentucky Station");
*(spacesP+30) = new Space(STREET,30,(char*)"Albany Avenue");
*(spacesP+31) = new Space(STREET,31,(char*)"South Shore Lane");
}
Board::~Board() {
// TODO Auto-generated destructor stub
for (int i = 0; i < 32; i ++) {
delete *(spacesP+i);
}
delete spacesP;
}
Space* Board::getSpace(int n) {
return (*(spacesP+n));
}
| true |
8d3072ba3a0537456a060fce4a403b2144a70d4b | C++ | halfclear/easynet | /test/SignalHandlerMgr.ut.cpp | UTF-8 | 8,084 | 2.6875 | 3 | [
"BSD-2-Clause"
] | permissive | #include <signal.h>
#include <sys/types.h>
#include <string.h>
#include <cstring>
#include <string>
#include <iostream>
#include "utils/TimeUtil.h"
#include <test_harness.h>
#include <thread>
#include <chrono>
#include <future>
#include <sys/wait.h>
#include "EventLoop.h"
#include "SignalHandler.h"
#include "SignalMgr.h"
#include "utils/log.h"
using namespace std;
using namespace easynet;
int testAddAndCloseInLoop(int sig)
{
Logger::getInstance().setLogLevel(Logger::LOG_LEVEL_INFO);
LOG_INFO("-----------------------------------------");
LOG_INFO("SignalHandlerMgr-testAddAndCloseInLoop signal:%d %s", sig, SignalMgr::getSignalName(sig).c_str());
LOG_INFO("----------------------------------------");
pid_t pid = ::fork();
if (pid < 0) {
LOG_ERROR("fork error");
return -1;
} else if (pid == 0) { // child
LOG_INFO("child starting----");
SignalMgr::enableSignalHandling();
EventLoop loop;
SignalHandler *handler1 = nullptr;
SignalHandler *handler2 = nullptr;
int cnt1 = 0;
int cnt2 = 0;
loop.runAfter(0, [&]{
int sigNum = sig;
handler1 = loop.addSignalHandler(sigNum, [&](){
cnt1++;
LOG_INFO("signal %d %s caught %d times by child handler1",
sigNum, SignalMgr::getSignalName(sigNum).c_str(), cnt1);
});
handler2 = loop.addSignalHandler(sigNum, [&](){
cnt2++;
LOG_INFO("signal %d %s caught %d times by child handler2",
sigNum, SignalMgr::getSignalName(sigNum).c_str(), cnt2);
});
});
loop.runAfter(200, [&]{
LOG_INFO("child to close all signal %d %s handlers",
sig, SignalMgr::getSignalName(sig).c_str());
handler1->close();
handler2->close();
EXPECT_EQ(1, cnt1);
EXPECT_EQ(1, cnt2);
});
loop.loop();
LOG_INFO("child exiting----");;
exit(0);
return 0;
} else { // parent
std::this_thread::sleep_for(std::chrono::milliseconds(100));
LOG_INFO("send signal %d %s to child %d", sig, SignalMgr::getSignalName(sig).c_str(), pid);
kill(pid, sig);
std::this_thread::sleep_for(std::chrono::milliseconds(300));
LOG_INFO("send signal %d %s again to child %d", sig, SignalMgr::getSignalName(sig).c_str(), pid);
kill(pid, sig);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
int status = 0;
pid_t ret = ::waitpid(pid, &status, 0);
LOG_INFO("child %d exited, exit status = %d", ret, status);
return status;
}
}
TEST(SignalHandlerMgr, testAddAndCloseInLoop)
{
LOG_INFO("-----------------------------------------------------");
LOG_INFO("SignalHandlerMgr-testAddAndCloseInLoop");
LOG_INFO("-----------------------------------------------------");
int status = 0;
status = testAddAndCloseInLoop(SIGHUP);
EXPECT_EQ(SIGHUP, status);
status = testAddAndCloseInLoop(SIGINT);
EXPECT_EQ(SIGINT, status);
status = testAddAndCloseInLoop(SIGQUIT);
EXPECT_EQ(SIGQUIT+128, status);
status = testAddAndCloseInLoop(SIGILL);
EXPECT_EQ(SIGILL+128, status);
status = testAddAndCloseInLoop(SIGTRAP);
EXPECT_EQ(SIGTRAP+128, status);
status = testAddAndCloseInLoop(SIGABRT);
EXPECT_EQ(SIGABRT+128, status);
status = testAddAndCloseInLoop(SIGBUS);
EXPECT_EQ(SIGBUS+128, status);
status = testAddAndCloseInLoop(SIGFPE);
EXPECT_EQ(SIGFPE+128, status);
status = testAddAndCloseInLoop(SIGKILL);
EXPECT_EQ(SIGKILL, status);
status = testAddAndCloseInLoop(SIGUSR1);
EXPECT_EQ(SIGUSR1, status);
status = testAddAndCloseInLoop(SIGSEGV);
EXPECT_EQ(SIGSEGV+128, status);
status = testAddAndCloseInLoop(SIGUSR2);
EXPECT_EQ(SIGUSR2, status);
status = testAddAndCloseInLoop(SIGPIPE);
EXPECT_EQ(SIGPIPE, status);
status = testAddAndCloseInLoop(SIGALRM);
EXPECT_EQ(SIGALRM, status);
status = testAddAndCloseInLoop(SIGTERM);
EXPECT_EQ(SIGTERM, status);
status = testAddAndCloseInLoop(SIGSTKFLT);
EXPECT_EQ(SIGSTKFLT, status);
status = testAddAndCloseInLoop(SIGXCPU);
EXPECT_EQ(SIGXCPU+128, status);
status = testAddAndCloseInLoop(SIGXFSZ);
EXPECT_EQ(SIGXFSZ+128, status);
status = testAddAndCloseInLoop(SIGVTALRM);
EXPECT_EQ(SIGVTALRM, status);
status = testAddAndCloseInLoop(SIGPROF);
EXPECT_EQ(SIGPROF, status);
status = testAddAndCloseInLoop(SIGIO);
EXPECT_EQ(SIGIO, status);
status = testAddAndCloseInLoop(SIGPWR);
EXPECT_EQ(SIGPWR, status);
status = testAddAndCloseInLoop(SIGSYS);
EXPECT_EQ(SIGSYS+128, status);
for (int i = SIGRTMIN; i <= SIGRTMAX; i++)
{
status = testAddAndCloseInLoop(i);
EXPECT_EQ(i, status);
}
}
int testAddAndCloseInHandler(int sig)
{
Logger::getInstance().setLogLevel(Logger::LOG_LEVEL_INFO);
LOG_INFO("-----------------------------------------");
LOG_INFO("SignalHandlerMgr-testAddAndCloseInHandler signal:%d %s", sig, SignalMgr::getSignalName(sig).c_str());
LOG_INFO("----------------------------------------");
pid_t pid = ::fork();
if (pid < 0) {
LOG_ERROR("fork error");
return -1;
} else if (pid == 0) { // child
LOG_INFO("child starting----");
SignalMgr::enableSignalHandling();
EventLoop loop;
SignalHandler *handler1 = nullptr;
SignalHandler *handler2 = nullptr;
SignalHandler *handler3 = nullptr;
SignalHandler *handler4 = nullptr;
int cnt1 = 0;
int cnt2 = 0;
int cnt3 = 0;
int cnt4 = 0;
handler1 = loop.addSignalHandler(sig, [&](){
cnt1++;
LOG_INFO("signal %d %s caught %d times by child handler1",
sig, SignalMgr::getSignalName(sig).c_str(), cnt1);
handler1->close();
});
handler2 = loop.addSignalHandler(sig, [&](){
cnt2++;
LOG_INFO("signal %d %s caught %d times by child handler2",
sig, SignalMgr::getSignalName(sig).c_str(), cnt2);
handler2->close();
handler3 = loop.addSignalHandler(sig, [&](){
cnt3++;
LOG_INFO("signal %d %s caught %d times by child handler3",
sig, SignalMgr::getSignalName(sig).c_str(), cnt3);
});
handler4 = loop.addSignalHandler(sig+1, [&](){
cnt4++;
LOG_INFO("signal %d %s caught %d times by child handler4",
sig+1, SignalMgr::getSignalName(sig+1).c_str(), cnt4);
});
});
loop.runAfter(300, [&]{
LOG_INFO("child to close all signal handlers");
handler3->close();
handler4->close();
EXPECT_EQ(1, cnt1);
EXPECT_EQ(1, cnt2);
EXPECT_EQ(2, cnt3);
EXPECT_EQ(1, cnt4);
});
loop.loop();
LOG_INFO("child exiting----");;
exit(0);
return 0;
} else { // parent
std::this_thread::sleep_for(std::chrono::milliseconds(100));
LOG_INFO("send signal %d %s to child %d", sig, SignalMgr::getSignalName(sig).c_str(), pid);
kill(pid, sig);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
LOG_INFO("send signal %d %s again to child %d", sig, SignalMgr::getSignalName(sig).c_str(), pid);
kill(pid, sig);
LOG_INFO("send signal %d %s to child %d", sig+1, SignalMgr::getSignalName(sig+1).c_str(), pid);
kill(pid, sig+1);
std::this_thread::sleep_for(std::chrono::milliseconds(400));
LOG_INFO("send signal %d %s again to child %d", sig, SignalMgr::getSignalName(sig).c_str(), pid);
kill(pid, sig);
int status = 0;
pid_t ret = ::waitpid(pid, &status, 0);
LOG_INFO("child %d exited, exit status = %d", ret, status);
return status;
}
}
TEST(SignalHandlerMgr, testAddAndCloseInHandler)
{
LOG_INFO("-----------------------------------------------------");
LOG_INFO("SignalHandlerMgr-testAddAndCloseInHandler");
LOG_INFO("-----------------------------------------------------");
int status = 0;
status = testAddAndCloseInHandler(SIGINT);
EXPECT_EQ(2, status);
status = testAddAndCloseInHandler(SIGABRT);
EXPECT_EQ(134, status);
}
| true |
56c4958d5ded0e122448820529462e7054445f79 | C++ | Cosmos547/rts_moving_simulation | /SceneTexture.cpp | UTF-8 | 458 | 2.640625 | 3 | [] | no_license | #include <SFML/Graphics.hpp>
#include <iostream>
#include "SceneTexture.h"
SceneTexture::SceneTexture(float xpos, float ypos, float xsize, float ysize, std::string textureName) : SceneObject(xpos, ypos, xsize, ysize) {
t.loadFromFile(textureName);
rect = sf::RectangleShape(sf::Vector2f(xsize, ysize));
rect.setPosition(xpos, ypos);
rect.setTexture(&t);
}
void SceneTexture::render(sf::RenderWindow* window) {
(*window).draw(rect);
}
| true |
528bd1ad3977d9f7b3b14d7ada97a1a491368d34 | C++ | perandersson/attributes | /attributes/MutableClass.cpp | UTF-8 | 8,243 | 2.6875 | 3 | [] | no_license | #include "MutableClass.h"
#include "MutableMethod.h"
#include "MutableAttribute.h"
#include "MutableClassLoader.h"
#include "MethodPostProcessor.h"
#include "ClassPostProcessor.h"
#include <algorithm>
#include <set>
static const string GetProcessorName(const string& className) {
return string("PostProcessor<" + className + ">");
}
MutableClass::MutableClass(const string& name, const type_info& type, IMutableConstructor* constructor, MutableClassLoader* classLoader)
: mName(name), mType(type), mConstructor(constructor), mClassLoader(classLoader)
{
}
MutableClass::~MutableClass()
{
}
void MutableClass::ConnectInheritedClasses()
{
for (auto className : mInheritsFrom) {
auto clazz = const_cast<MutableClass*>(static_cast<const MutableClass*>(mClassLoader->FindClass(className)));
if (clazz != nullptr) {
mInheritsFromClasses.push_back(clazz);
clazz->InheritedBy(this);
}
}
}
void MutableClass::ConnectAttributes()
{
for (auto parent : mInheritsFromClasses) {
mAttributes.CollectAttributesFromParent(&parent->mAttributes);
}
}
void MutableClass::ConnectMethods()
{
for (auto parent : mClassLoader->FindParentClasses(this->GetName())) {
for (auto methodPair : mMethods) {
auto method = static_cast<MutableMethod*>(methodPair.second.get());
auto parentMethod = static_cast<const MutableMethod*>(parent->GetMethod(method));
if (parentMethod != nullptr) {
method->CollectAttributesFromParent(parentMethod);
}
}
}
}
void MutableClass::AttachPostProcessors()
{
const auto processorName = GetProcessorName(mName);
const auto extendedClasses = mClassLoader->FindExtendedClasses(processorName);
for (auto clazz : extendedClasses) {
AttachPostProcessorsForClass(static_cast<const MutableClass*>(clazz));
}
for (auto clazz : mInheritsFromClasses) {
const auto processorName = GetProcessorName(clazz->GetName());
const auto extendedClasses = mClassLoader->FindExtendedClasses(processorName);
for (auto clazz : extendedClasses) {
AttachPostProcessorsForClass(static_cast<const MutableClass*>(clazz));
}
}
}
void MutableClass::AttachPostProcessorsForClass(const MutableClass* clazz)
{
if (clazz->InterceptsClass(this)) {
auto postProcessor = reinterpret_cast<IPostProcessor*>(clazz->NewInstance());
auto instance = shared_ptr<IPostProcessor>(postProcessor);
mPostProcessors.push_back(shared_ptr<IPostProcessorDelegate>(new ClassPostProcessor(instance)));
}
for (auto& method : mMethods) {
auto mutableMethod = static_cast<const MutableMethod*>(method.second.get());
if (clazz->InterceptsMethod(this, mutableMethod)) {
auto postProcessor = reinterpret_cast<IPostProcessor*>(clazz->NewInstance());
auto instance = shared_ptr<IPostProcessor>(postProcessor);
mPostProcessors.push_back(shared_ptr<IPostProcessorDelegate>(new MethodPostProcessor(instance, mutableMethod)));
}
}
}
set<string> MutableClass::CollectClassAttributes() const
{
set<string> result;
for (auto attributeName : mAttributes.GetAttributeNames()) {
result.insert(attributeName);
}
for (auto clazz : mInheritsFromClasses) {
auto attributes = clazz->CollectClassAttributes();
result.insert(attributes.begin(), attributes.end());
}
return result;
}
set<string> MutableClass::CollectMethodAttributes(const MutableMethod* method) const
{
set<string> result;
for (auto attribute : method->GetAttributes()) {
result.insert(attribute->GetName());
}
for (auto clazz : mInheritsFromClasses) {
auto inheritedMethod = clazz->GetMethod(method);
if (inheritedMethod != nullptr) {
auto attributes = clazz->CollectMethodAttributes(static_cast<const MutableMethod*>(inheritedMethod));
result.insert(attributes.begin(), attributes.end());
}
}
return result;
}
vector<string> MutableClass::InterceptAttributes() const
{
auto interceptor = GetInterceptor();
if (interceptor != nullptr) {
return interceptor->GetParameters();
}
return vector<string>();
}
bool MutableClass::InterceptsClass(const MutableClass* clazz) const
{
for (auto intercept : InterceptAttributes()) {
set<string> attributes = clazz->CollectClassAttributes();
for (auto attribute : attributes) {
if (intercept == attribute) {
return true;
}
}
}
return false;
}
bool MutableClass::InterceptsMethod(const MutableClass* clazz, const MutableMethod* method) const
{
for (auto intercept : InterceptAttributes()) {
set<string> attributes = clazz->CollectMethodAttributes(method);
for (auto attribute : attributes) {
if (intercept == attribute) {
return true;
}
}
}
return false;
}
const IAttribute* MutableClass::GetInterceptor() const
{
static const string INTERCEPTOR_NAME(STRINGIFY(INTERCEPTS));
auto attributes = mAttributes.GetAttributes();
for (auto attribute : attributes) {
if (attribute->GetName() == INTERCEPTOR_NAME) {
return attribute;
}
}
return &_unavailableAttribute;
}
void MutableClass::InheritedBy(const MutableClass* clazz)
{
mInheritedBy.push_back(clazz->GetName());
mInheritedByClasses.push_back(clazz);
}
bool MutableClass::IsImplementedBy(const string& className) const
{
for (auto clazz : mInheritedByClasses) {
if (clazz->GetName() == className) {
return true;
}
}
return false;
}
bool MutableClass::Implements(const string& className) const
{
for (auto clazz : mInheritsFromClasses) {
if (clazz->GetName() == className) {
return true;
}
if (clazz->Implements(className)) {
return true;
}
}
for (auto& name : mInheritsFrom) {
if (className == name) {
return true;
}
}
return false;
}
void* MutableClass::NewInstance() const
{
void* instance = mConstructor->NewInstance();
for (auto postProcessor : mPostProcessors) {
postProcessor->Process(this, instance);
}
return instance;
}
IClassInterceptor* MutableClass::CastToInterceptor(void* ptr) const
{
return mConstructor->CastToInterceptor(ptr);
}
IPostProcessor* MutableClass::CastToProcessor(void* ptr) const
{
return mConstructor->CastToProcessor(ptr);
}
const string& MutableClass::GetName() const
{
return mName;
}
vector<const IMethod*> MutableClass::GetMethods() const
{
vector<const IMethod*> result;
for (auto& method : mMethods) {
result.push_back(method.second.get());
}
return result;
}
const IMethod* MutableClass::GetMethod(const string& name, const string& signature) const
{
auto it = mMethods.find(name + "+" + signature);
if (it == mMethods.end()) {
for (auto clazz : mInheritsFromClasses) {
auto method = clazz->GetMethod(name, signature);
if (method != nullptr) {
return method;
}
}
return nullptr;
}
return it->second.get();
}
const IMethod* MutableClass::GetMethod(const IMethod* method) const
{
auto& name = method->GetName();
auto& signature = method->GetSignature();
return GetMethod(name, signature);
}
vector<const IAttribute*> MutableClass::GetAttributes() const
{
vector<const IAttribute*> result = mAttributes.GetAttributes();
for (auto clazz : mInheritsFromClasses) {
auto attributes = clazz->GetAttributes();
result.insert(result.end(), attributes.begin(), attributes.end());
}
return result;
}
const IAttribute* MutableClass::FindAttribute(const string& name) const
{
return FindAttribute(name, true);
}
const IAttribute* MutableClass::FindAttribute(const string& name, bool includeInherited) const
{
auto attribute = mAttributes.FindAttribute(name);
if (attribute->Exists()) {
return attribute;
}
if (!includeInherited) {
return &_unavailableAttribute;
}
for (auto clazz : mInheritsFromClasses) {
auto attribute = clazz->FindAttribute(name, includeInherited);
if (attribute->Exists()) {
return attribute;
}
}
return &_unavailableAttribute;
}
void MutableClass::InheritsFrom(const string& name)
{
mInheritsFrom.push_back(name);
}
IMutableAttribute* MutableClass::RegisterAttribute(const string& name)
{
return mAttributes.RegisterAttribute(name);
}
IMutableMethod* MutableClass::RegisterMethod(const string& name, const string& signature, IRawMethod* rm)
{
auto method = shared_ptr<MutableMethod>(new MutableMethod(name, signature, rm));
mMethods.insert(make_pair(name + "+" + signature, method));
return method.get();
}
const IConstructor* MutableClass::GetConstructor() const
{
return mConstructor;
}
| true |
ceb4679f2212bcb7b5b779efb78071dc24a78a2e | C++ | rishabhSharmaOfficial/CompetitiveProgramming | /MustDo_GeeksForGeeks/Arrays/inversion-of-array.cpp | UTF-8 | 1,633 | 3.40625 | 3 | [] | no_license | /*
Count inversions of array
pairs such that
a[i] > a[j] and i < j
*/
/*
Approach 1 - Check every pair O(n^2)
Approach 2 - Use Merge Sort O(nlogn)
Merge sort's merge step gives us two sorted arrays left half and right half
example -
12345 134
if L[i] > R[j]
then all pairs -> (i,j) (i+1,j) (i+2,j) ... (n1-1,j) are inversions (count: n1-i)
because left half elements are never moved over to the right hence what were inversions will remain inversions
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAXN 1000
vector<ll> arr(MAXN);
ll merge(int l, int m, int r)
{
int n1 = m - l + 1;
int n2 = r - m;
vector<ll> L(n1), R(n2);
for(int i = 0; i < n1; i++)
L[i] = arr[l + i];
for(int i = 0; i < n2; i++)
R[i] = arr[m + 1 + i];
int i = 0, j = 0, k = l;
ll inv_count = 0;
while(i < n1 && j < n2)
{
if(L[i] <= R[j])
arr[k] = L[i], i++;
else
arr[k] = R[j], j++, inv_count += n1 - i;
k++;
}
while(i < n1)
arr[k] = L[i], i++, k++;
while(j < n2)
arr[k] = R[j], j++, k++;
return inv_count;
}
ll mergeSort(int l, int r)
{
if(l >= r)
return 0;
int m = (l + r) / 2;
ll left = mergeSort(l, m);
ll right = mergeSort(m + 1, r);
ll mid = merge(l, m, r);
return left + right + mid;
}
int main()
{
// FASTIO;
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
for(int i = 0; i < n; i++)
cin >> arr[i];
ll ans = mergeSort(0, n - 1);
cout << ans << endl;
}
return 0;
} | true |
4a952de2daebdfded91094290ab09737be16a19f | C++ | jgrugru/arduino_projects | /ultrasonic_accuracy_test/ultrasonic_accuracy_test.ino | UTF-8 | 726 | 3.09375 | 3 | [] | no_license |
//specify pins for communicating with the sensor
byte trig_pin = 10;
byte echo_pin = 9;
//list all function headers
void sendPulse();
double calculateDistance(double);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(trig_pin, OUTPUT);
pinMode(echo_pin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//Code for the ultrasonic sensor
double duration;
sendPulse();
duration = pulseIn(echo_pin, HIGH);
Serial.println(calculateDistance(duration));
}
void sendPulse() {
digitalWrite(trig_pin, LOW);
delayMicroseconds(10);
digitalWrite(trig_pin, HIGH);
}
double calculateDistance(double duration) {
return (0.034 * (duration)) / 2.0;
}
| true |
d1fb04b752b2840345d4572ce4b76e17e05b0c46 | C++ | zhanrui/apollo | /bmjcui/src/state/common/checktaskgroup.cpp | UTF-8 | 2,866 | 2.5625 | 3 | [] | no_license | #include "checktaskgroup.h"
#include "checktask.h"
#include <QList>
CheckTaskGroup::CheckTaskGroup(QObject* parent,const QString& scenename, const int weight, const QList<CheckTask*> & tasks)
: QObject(parent)
{
this->enabled = true;
this->weight = weight;
this->scenename = scenename;
this->start = false;
currentstatus = QString();
errorfind = false;
totalproblems = 0;
totalinfomations = 0;
totalcompleteunit=0;
currentcompleteunit=0;
initConnect(tasks);
}
CheckTaskGroup::~CheckTaskGroup()
{
}
void CheckTaskGroup::initConnect(const QList<CheckTask*> & tasks)
{
for (CheckTask* task : tasks) {
connect(this, SIGNAL(startSig()), task, SLOT(startExecute()));
connect(this, SIGNAL(stopSig()), task, SLOT(stopExecute()));
connect(this, SIGNAL(disableSig()), task, SLOT(disableTask()));
connect(this, SIGNAL(enableSig()), task, SLOT(enableTask()));
connect(task, SIGNAL(dataCountUpdateSig(const int ,const int)), this, SLOT(dataCountUpdate(const int ,const int)));
connect(task, SIGNAL(progressUpdateSig(const int ,const QString &)), this, SLOT(progressUpdate(const int , const QString &)));
connect(task, SIGNAL(totalUnitChangedSig(const int )), this, SLOT(totalUnitChanged(const int)));
this->totalcompleteunit += task->weight*100;
}
}
//Call From State/UI
void CheckTaskGroup::startExecute()
{
if (this->enabled) {
this->start = true;
this->currentcompleteunit = 0;
currentstatus.clear();
errorfind = false;
totalproblems = 0;
totalinfomations = 0;
}
emit startSig();
}
void CheckTaskGroup::stopExecute()
{
this->start = false;
emit stopSig();
}
void CheckTaskGroup::disableGroup()
{
this->enabled = false;
emit disableSig();
}
void CheckTaskGroup::enableGroup()
{
this->enabled = true;
emit enableSig();
}
void CheckTaskGroup::totalUnitChanged(const int value){
totalcompleteunit+=value;
emit totalUnitChangedSig(value * weight);
}
void CheckTaskGroup::progressUpdate(const int completeuint,const QString & status){
this->currentcompleteunit +=completeuint;
this->currentstatus = status;
emit progressUpdateSig(completeuint*weight,status);
emit completerateUpdateSig(currentcompleteunit*100/totalcompleteunit,status);
if(this->currentcompleteunit == this->totalcompleteunit ){
this->start = false;
emit completeSig();
}
}
void CheckTaskGroup::dataCountUpdate(const int totalproblems ,const int totalinfomations){
this->totalproblems += totalproblems;
this->totalinfomations += totalinfomations;
if(totalproblems>0){
if(!errorfind){
errorfind = true;
emit errorFindSig();
}
}
emit dataCountUpdateSig(totalproblems, totalinfomations);
}
| true |
9def292c6f8479bad39eb7dfd4f3897b83e0cb1b | C++ | BilalAli181999/Programming-Fundamentals-in-C_Plus_Plus | /Call charges/Call charges/Source.cpp | UTF-8 | 1,740 | 3.09375 | 3 | [] | no_license | #include<iostream>
using namespace std;
int main()
{
float startingTime, noMinutes;
cout << "Enter starting time";
cin >> startingTime;
cout << "Enter no of Minutes";
cin >> noMinutes;
float totalTime;
totalTime = startingTime +( noMinutes/60);
int a,b;
int minutes = totalTime - (int)totalTime;
if (minutes > 59)
{
totalTime = totalTime + 1;
minutes = minutes - 59;
}
if (totalTime >= 00.00 && totalTime <= 23.59 && minutes <= 59)
{
if (totalTime >= 00.00 && totalTime <= 06.59)
{
cout << "charges" << " " << (int(totalTime)*60+minutes)*0.12;
}
if (startingTime >= 00.00 && startingTime<=06.59 && totalTime>=07.00 && totalTime <= 19.00)
{
b = totalTime - 06.59;
a = (int(b) * 60 + minutes)*0.55;
cout << "charges" << " " << ((int(06.59) * 60 + minutes)*0.12) + a;
}
if (startingTime >= 00.00 && startingTime <= 06.59 && totalTime >= 19.01 && totalTime <= 23.59)
{
b = totalTime - 19.00;
a = (int(b) * 60 + minutes)*0.35;
cout << "charges" << " " << ((int(06.59) * 60 + minutes)*0.12) + ((int(06.59) * 60 + minutes)*0.55) + a;
}
if (startingTime >= 07.00 && startingTime <= 19.00 && totalTime >= 07.00 && totalTime <= 19.00)
{
cout << "charges" << " " << (int(totalTime) * 60 + minutes)*0.55;
}
if (startingTime >= 07.00 && startingTime <= 19.00 && totalTime >= 19.01 && totalTime <= 23.59)
{
b = totalTime - 06.59;
a = (int(b) * 60 + minutes)*0.35;
cout << "charges" << " " << ((int(totalTime) * 60 + minutes)*0.55)+a;
}
if (startingTime >= 19.00 && startingTime <= 23.59 && totalTime >= 19.00 && totalTime <= 23.59)
{
cout << "charges" << " " << (int(totalTime) * 60 + minutes)*0.55;
}
}
else
{
cout << "faulty input";
}
return 0;
} | true |
0db180cd9c798dd4452e77ba20280a37307bb152 | C++ | LeeDoona/Algorithm | /Sudoku/main.cpp | UTF-8 | 626 | 2.71875 | 3 | [] | no_license | #include "sudoku.h"
#pragma warning(disable:4996)
#pragma warning(disable:4101) //didn't use variable
int main()
{
int i, j, k;
int testNum;
FILE *inFile = fopen("input.txt", "r");
fscanf(inFile, "%d", &testNum);
try
{
if(inFile == NULL) throw InputFileError;
}catch(int InputFileError) {
printf("input file error\n");
return 0;
}
for(i=0; i<testNum; i++) {
sudoku solver(true, true, true);
for (j = 0; j < 9; j++){
for (k = 0; k < 9; k++){
fscanf(inFile, "%d ", &solver.gameBoard[j][k]);
}
}
solver.solveSudoku(BruteForce);
solver.printSolution();
}
fclose(inFile);
return 0;
} | true |