Unite getPosUnite(Position a) { Unite[] items = Unites(); foreach (Unite t in items) if (cmpPos(t.Pos, a)) return t; throw new Exception(); //No unit }
bool cmpPos(Position a, Position b) { return a.X == b.X && a.Y == b.Y; }
int distPos(Position a, Position b) { return Math.Max(Math.Abs(a.X - b.X), Math.Abs(a.Y - b.Y)); }
public static extern Erreur AcheterObjet(Position cible, TypeObjet objet);
public static extern Erreur Deguisement(Position cible, TypeUnite nouveau_type);
public static extern Erreur Deplacer(Position cible, Position pos);
public int Valeur; // <- la valeur de la piece. #endregion Fields #region Constructors public Piece() { PosPiece = new Position(); }
public static extern Erreur Enrouler(int id, Position point);
public static extern Erreur Fusionner(int id1, Position pos1, int id2, Position pos2);
public static extern Erreur CouperTraineeMoto(int id, Position entre, Position et);
public static extern Erreur Deplacer(int id, Position de, Position vers);
public static extern Erreur Attaquer(Position attaquant, Position cible);
public static extern Erreur Relever(Position cible);
public static extern Erreur Potion(Position cible);
Position minDistPos(Position a, Position b, Position goalPos) { Position re = new Position(); if (distPos(goalPos, a) > distPos(goalPos, b)) { re.X = b.X; re.Y = b.Y; } else { re.X = a.X; re.Y = a.Y; } return re; }
public static extern Erreur PoserPointCroisement(Position point);
public void Jouer() { Unite[] tmpu = Unites(); Unite uTiti = new Unite(); //Prevent warning foreach (Unite item in tmpu) if (item.Ennemi && item.VraiTypeUnite == TypeUnite.PERROQUET) { uTiti = item; break; } bool MADE_ACTIONS = true; while (NombrePc() > 0 && MADE_ACTIONS) { Unite[] t = Unites(); MADE_ACTIONS = false; if (t.Length > 0) { Unite min = null; foreach (Unite item in t) if (!item.Ennemi && item.VraiTypeUnite == item.TypeUniteActuel && item.TypeUniteActuel == TypeUnite.CHAT && item.Ko < 0 && item.Pa > 0) if (min != null) min = getPosUnite(minDistPos(min.Pos, item.Pos, uTiti.Pos)); //Seeking the closest cat to ennemy's titi else min = item; if (min != null) if (distPos(min.Pos, uTiti.Pos) == 1 && Attaquer(min.Pos, uTiti.Pos) == Erreur.OK) break; //We wone else //We have to move our cat to the closest position to titi { Position closest = new Position(); closest.X = min.Pos.X; closest.Y = min.Pos.Y; TailleTerrain mapbound = TailleTerrainActuelle(); int minx = (min.Pos.X - min.Pa) >= mapbound.MinCoord ? min.Pos.X - min.Pa : mapbound.MinCoord; int minyI = (min.Pos.Y - min.Pa) >= mapbound.MinCoord ? min.Pos.Y - min.Pa : mapbound.MinCoord; int maxx = (min.Pos.X + min.Pa) < mapbound.MaxCoord ? min.Pos.X + min.Pa : mapbound.MaxCoord; int maxy = (min.Pos.Y + min.Pa) < mapbound.MaxCoord ? min.Pos.Y + min.Pa : mapbound.MaxCoord; for (; minx < maxx; minx++) for (int miny = minyI; miny < maxy; miny++) { Position tmppos = new Position(); tmppos.X = minx; tmppos.Y = miny; try { getPosUnite(tmppos); //Will throw an error in case of no Unite } catch { closest = minDistPos(closest, tmppos, uTiti.Pos); } } if (!cmpPos(min.Pos, closest)) { Deplacer(min.Pos, closest); MADE_ACTIONS = true; } } } } try { Unite uniteonspawn = getPosUnite(PosRenfort(false)); if (uniteonspawn.VraiTypeUnite == TypeUnite.PERROQUET) { Position newpos = new Position(); newpos.X = uniteonspawn.Pos.X; newpos.Y = uniteonspawn.Pos.Y; newpos.X--; Deplacer(uniteonspawn.Pos, newpos); } } catch { Renfort(TypeUnite.CHAT); //Will be available next turn } }
public static extern TypeBonus RegarderTypeBonus(Position pos);
public static extern Erreur Utiliser(Position attaquant, Position cible);
public static extern TypeCase RegarderTypeCase(Position pos);
public int Team; // <- donne l'equipe du joueur #endregion Fields #region Constructors public Unite() { PosUnite = new Position(); }
public Position Pos; // <- position de la source d'énergie #endregion Fields #region Constructors public SourceEnergie() { Pos = new Position(); }
public static extern void AfficherPosition(Position v);
public static extern Erreur Banzai(Position cible);