CustomGame.GetGameState();
Syntax
public GameState GetGameState()

Returns a CustomGameOW.GameState enum of the current state of the game.
In lobby: GameState.InLobby
Waiting For Players: GameState.Waiting
Playing POTG: GameState.Ending_POTG
Commending: GameState.Ending_Commend

The example below will wait for the game to end, then swap both teams to keep the same people attacking/defending.

using System;
using CustomGameOW;

...

static void Main(string[] args)
{
    // Swap players on both teams at end of game to prevent defend/attack rotation.

    CustomGame cg = new CustomGame();

    while(true)
    {
        if (cg.GetGameState() == GameState.Ending_Commend)
        {
            cg.SwapAll();
            cg.ClickOption(GameOption.Restart);
        }
    }
}

See also:

CustomGame.SwapAll()