# Rectangle formation c++

**URL:** <https://discourse.codecombat.com/t/rectangle-formation-c/36286>\
**Category:** Uncategorized\
**Created:** [November 1, 2023, 12:34am UTC](https://discourse.codecombat.com/t/rectangle-formation-c/36286 "2023-11-01T00:34:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![itik](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/itik/32/28431_2.png) [@itik](https://discourse.codecombat.com/u/itik)\
**Post date:** [November 1, 2023, 12:34am UTC](https://discourse.codecombat.com/t/rectangle-formation-c/36286/1 "2023-11-01T00:34:10Z")

</div>

```python
// Form up soldiers and archers in rectangle formations.

int main() {
    // The distance between units.
    auto step = 8;
    
    // First form up soldiers.
    auto sergeant = hero.findNearest(hero.findByType("soldier"));
    // The coordinates of the bottom left corner.
    auto soldierX = 8;
    auto soldierY = 8;
    // The width and height of the formation.
    auto width = sergeant.rectWidth;
    auto height = sergeant.rectHeight;
    
    for (float x = soldierX; x <= soldierX + width; x += 8) {
        for (float y = soldierY; y <= soldierY + height; y += 8) {
            hero.summon("soldier");
            auto lastUnit = hero.built[hero.built.size()-1];
            // Command the last built unit by using the x/y variables:
            hero.command(lastUnit, "move", {'x':x, 'y':y })
        }
    }
    
    // Next form up archers.
    auto sniper = hero.findNearest(hero.findByType("archer"));
    // The coordinates of the bottom left corner.
    auto archerX1 = 48;
    auto archerY1 = 8;
    // The coordinates of the top right corner.
    auto archerX2 = sniper.archerX2;
    auto archerY2 = sniper.archerY2;
    
    for (float x = archerX1; x <= archerX2; x += 8) {
        for (float y = archerY1; y <= archerY2; y += 8) {
            // Summon an archer.
            hero.summon("archer");
            // Find the last built unit.
            auto lastUnit = hero.built[len(hero.built)-1];
            // Command the last built unit by using the x/y variables:
            hero.command(lastUnit, "move", {'x':x, 'y':y })
        }
    }
    
    return 0;
}

```

erorr on hero.command()
