bool Board::ValidPieceSpot(Piece loc) { //get's all current positions on board //Get all possible occupied space //Get availability grid int available[10][10]; bool check = GetAvailabilityGrid(available); if (check == false) { //delete available; return false; } vector<Coordinate> ls; ls = loc.GetOccupiedSpace(); //check if each occupied space is valid for (int i = 0; i < getPieceLength(loc.Type); i++) { //if out of bounds instantly false if (ls[i].x < 0 || ls[i].x > 9 || ls[i].y < 0 || ls[i].y > 9) { return false; } //if spot is already taken, return false if (available[ls[i].x][ls[i].y] != 0) { return false; } } return true; }
void UI::RenderToGrid (WINDOW* wnd, Piece pc, char* l) { vector<Coordinate> ls = pc.GetOccupiedSpace(); // for (auto c: ls) { if (c.x < 0 || c.x > 9 || c.y < 0 || c.y > 9) { break; } else { mvwprintw(wnd, (c.x * 2) + 3, (c.y * 2) + 4, l); } } }
Piece *Board::GetPieceAtCoordinate(Coordinate c) { if (c.x < 0 || c.x > 9 || c.y < 0 || c.y > 9) { return NULL; } vector<Coordinate> ls; //Get's all pieces //for (auto pc : BoardPieces) { for (uint8_t i = 0; i < BoardPieces.size(); i++){ Piece pc = BoardPieces.at(i); ls = pc.GetOccupiedSpace(); for (int i = 0; i < getPieceLength(pc.Type); i++) { if (ls[i].x == c.x && ls[i].y == c.y) { return &BoardPieces[i]; } } } return NULL; }