BWAPI
|
00001 #pragma once 00002 #include <math.h> 00003 #include <stdlib.h> 00004 #include <stdio.h> 00005 #include <BWAPI.h> 00006 00007 struct Vec { 00008 friend std::ostream& operator <<(std::ostream& os, const Vec& v); 00009 double x, y; 00010 Vec(double x_=0.0, double y_=0.0){ x=x_; y=y_; } 00011 Vec(const Vec& v){ x=v.x; y=v.y; } 00012 Vec(const BWAPI::Position& p){ x=p.x(); y=p.y(); } 00013 bool operator<(const Vec &b) const { return (x < b.x || (x == b.x && y < b.y)); } 00014 Vec operator+(const Vec &b) const { return Vec(x+b.x,y+b.y); } 00015 Vec operator+(const BWAPI::Position& p) { return BWAPI::Position(p.x() + (int)x, p.y() + (int)y); } 00016 Vec operator+=(const Vec &b) { x += b.x; y += b.y; return *this; } 00017 Vec operator+=(const BWAPI::Position& p) { x += p.x(); y += p.y(); return *this; } 00018 Vec operator+=(const BWAPI::TilePosition& p) { x += p.x(); y += p.y(); return *this; } 00019 Vec operator-(const Vec &b) const { return Vec(x-b.x,y-b.y); } 00020 Vec operator*(double b) const { return Vec(x*b,y*b); } 00021 Vec operator*=(const double b) { x *= b; y *= b; return *this; } 00022 Vec operator/(double b) const { return Vec(x/b,y/b); } 00023 Vec operator/=(const double s) { x /= s; y /= s; return *this; } 00024 bool operator==(const Vec &b) { return (x==b.x && y==b.y); } 00025 bool operator!=(const Vec &b) { return (x!=b.x || y!=b.y); } 00026 Vec mult(const Vec &b) const { return Vec(x*b.x,y*b.y); } 00027 Vec& normalize() { return (x == 0 && y == 0) ? *this : *this = *this * (1/sqrt(x*x+y*y)); } 00028 double norm() const { return sqrt(x*x+y*y); } 00029 double dot(const Vec &b) const { return x*b.x+y*b.y; } // cross: 00030 BWAPI::Position toPosition() const { return BWAPI::Position( (int)x, (int)y);}; 00031 BWAPI::TilePosition toTilePosition() const { return BWAPI::TilePosition( (int)x, (int)y);}; 00032 Vec operator%(Vec&b){return Vec(-y*b.x-x*b.y, x*b.y-y*b.x);} 00033 BWAPI::Position translate(const BWAPI::Position& p) const { return BWAPI::Position(p.x() + (int)x, p.y() + (int)y); } // sanitize? (map boundaries) 00034 BWAPI::Position translate(const Vec& v) const { return BWAPI::Position((int)v.x + (int)x, (int)v.y + (int)y); } // sanitize? (map boundaries) 00035 Vec vecTranslate(const Vec& v) const { return Vec((int)v.x + (int)x, (int)v.y + (int)y); } 00036 std::ostream& operator <<(std::ostream& os) const { os << x << " " << y; return os; } 00037 }; 00038 00039 inline std::ostream& operator <<(std::ostream& os, const Vec& v) { os << v.x << " " << v.y; return os; }