コード例 #1
0
 protected AIPlayerData(int position, string path, string logname, AIEventInterfaceI aiEvent, AICommandInterfaceI command, AIQueryI query, AICheatI cheat, int logLevel)
     : base(position, path, logname, aiEvent, command, query, cheat, logLevel)
 {
     dlogger_ = new CSubLog("PlayerData:" + Convert.ToString(position), realLog_);
     dlogger_.info("D Logger Log Open: " + path + " " + logname);
     random_ = new CMTRandom();
 }
コード例 #2
0
        private void updateUnit(CUpdate cup, CSubLog logger)
        {
            CUnit cu = getObjectById(cup.gid_);

            if (cu == null)
            {
                throw new Exception("Missing Unit in update: " + cup.gid_);
            }
            //firstly, is this an order update
            if (cup.order_ != null)
            {
                cu.ord_ = cup.order_;
                return;
            }

            foreach (string uptype in cup.updates_.Keys)
            {
                string value = cup.updates_[uptype];

                if (!cu.update(uptype, value, logger))
                {
                    if (aiLogging_)
                    {
                        dlogger_.info("Missing Update for " + uptype);
                    }
                    continue;
                }
            }
        }
コード例 #3
0
        ////////////////////////////////////////////////////////////
        //Start Turn -  This event is sent at the beginning of
        //your turn. Includes data like production results
        private void processStartTurn(CStartTurn ste, CSubLog logger)
        {
            curturn_ = ste.turn_;
            addUnits(ste.unitAdds_);
            if (ste.updates_ != null)
            {
                for (int i = 0; i < ste.updates_.Count; i++)
                {
                    updateUnit(ste.updates_[i], logger);
                }
            }
            //Note, props are really invalid after your turn ends
            proposals_.Clear();
            if (ste.proposals_ != null)
            {
                foreach (CProposal p in ste.proposals_)
                {
                    proposals_.Add(p);
                }
            }

            prodReport_.Clear();
            if (ste.prodData_ != null)
            {
                foreach (CProductionReportData prd in ste.prodData_)
                {
                    prodReport_.Add(prd);
                }
            }
        }
コード例 #4
0
        public VlasovPlayer(
            int position,
            Dictionary <string, string> caMap,
            CEncodedObjectInputBufferI bin,
            string logpath,
            string logname,
            AIEventInterfaceI aiEvent,
            AICommandInterfaceI command,
            AIQueryI query,
            AICheatI cheat,
            int logLevel)
            : base(
                position,
                logpath,
                logname,
                caMap,
                bin,
                aiEvent,
                command,
                query,
                cheat,
                logLevel)
        {
            elogger_ = new CSubLog("ExamplePlayer:" + Convert.ToString(position), realLog_);
            elogger_.info("D Logger Log Open: " + logpath + " " + logname);
            elogger_.info("Position " + Convert.ToSingle(position) + " waking up.");

            testAttribute_ = EncodeUtil.parseInt(caMap[TEST_ATTR]);

            hints_ = new CDLLHints(bin);
        }
コード例 #5
0
ファイル: AIPlayer.cs プロジェクト: OlegYurchik/edce-ai
 public void processEvents(Queue <CGameEvent> evec, CSubLog logger)
 {
     while (!holdFlag_ && evec.Count > 0)
     {
         CGameEvent ge = evec.Dequeue();
         //update the sequence to mark event as received
         processEvent(ge, alogger_);
     }
 }
コード例 #6
0
ファイル: AIPlayer.cs プロジェクト: OlegYurchik/edce-ai
        //////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////
        protected AIPlayer(int position, string path, string logname, AIEventInterfaceI aiEvent, AICommandInterfaceI command, AIQueryI query, AICheatI cheat, int logLevel)
        {
            position_ = position;
            realLog_  = new CLog(path, logname, logLevel);
            alogger_  = new CSubLog("AIPlayer" + Convert.ToString(position_), realLog_);
            alogger_.info("A Logger Log Open: " + path + " " + logname);

            aiEvent_ = aiEvent;
            command_ = command;
            query_   = query;
            cheat_   = cheat;
        }
コード例 #7
0
        public VlasovPlayer(int position, string pname, string logpath, string logname,
                            CDLLHints hints, AIEventInterfaceI aiEvent,
                            AICommandInterfaceI command, AIQueryI query, AICheatI cheat,
                            int logLevel) : base(position, logpath, logname, aiEvent, command,
                                                 query, cheat, logLevel)
        {
            elogger_ = new CSubLog("Vlasov Player:" + Convert.ToString(position), realLog_);
            elogger_.info("D Logger Log Open: " + logpath + " " + logname);
            elogger_.info(pname + " waking up");

            hints_ = hints.copy();

            pname_ = pname;
        }
コード例 #8
0
ファイル: AIPlayer.cs プロジェクト: OlegYurchik/edce-ai
        // ReSharper disable UnusedParameter.Local
        protected AIPlayer(
            int position,
            string path,
            string logname,
            Dictionary <string, string> caMap,
            CEncodedObjectInputBufferI bin,
            AIEventInterfaceI aiEvent,
            AICommandInterfaceI command,
            AIQueryI query,
            AICheatI cheat,
            int logLevel)
        // ReSharper restore UnusedParameter.Local
        {
            position_ = position;
            realLog_  = new CLog(path, logname, logLevel);
            alogger_  = new CSubLog("AIPlayer:" + Convert.ToString(position_), realLog_);

            aiEvent_ = aiEvent;
            command_ = command;
            query_   = query;
            cheat_   = cheat;
        }
コード例 #9
0
        public virtual void prepare(
            int mapWidth,
            bool horzWrap,
            int mapHeight,
            bool vertWrap,
            CDLLHints hints,
            CGameMapParameters mparams,
            WBQueryI unitData,
            StringPollerI distributor,
            MapCallbackI callback,
            string logpath,
            string logname,
            int loglevel)
        {
            if (reallogger_ == null)
            {
                reallogger_ = new CLog(logpath, logname, loglevel);
                logger_     = new CSubLog("MapMaker", reallogger_);
            }
            distributor_ = distributor;
            callback_    = callback;

            unitData_ = unitData;

            mapUtil_ = new CMapUtil(mapWidth, horzWrap, mapHeight, vertWrap);

            mparams_ = mparams;

            //build the map output
            for (int i = 0; i < mapWidth * mapHeight; i++)
            {
                mapLocs_.Add(new TempMapStruct());
            }

            //the default seed - object may get replaced
            random_ = new CMTRandom();
        }
コード例 #10
0
ファイル: AIPlayer.cs プロジェクト: OlegYurchik/edce-ai
 public virtual void processEvent(CGameEvent ge, CSubLog logger)
 {
     //Here You Would Deal With The Event By Looking
     //At It's Type and taking appropriate action
     //if need be
 }
コード例 #11
0
ファイル: LoopCheck.cs プロジェクト: OlegYurchik/edce-ai
 public void setLog(CSubLog logger)
 {
     logger_ = logger;
 }
コード例 #12
0
        ////////////////////////////////////////////////////////////////////
        //Reloading
        protected AIPlayerData(
            int position,
            string path,
            string logname,
            Dictionary <string, string> caMap,
            CEncodedObjectInputBufferI bin,
            AIEventInterfaceI aiEvent,
            AICommandInterfaceI command,
            AIQueryI query,
            AICheatI cheat,
            int logLevel)
            : base(position, path, logname, caMap, bin, aiEvent, command, query, cheat, logLevel)
        {
            dlogger_ = new CSubLog("PlayerData:" + Convert.ToString(position), realLog_);


            curturn_          = EncodeUtil.parseInt(caMap[CUR_TURN]);
            numPlayers_       = EncodeUtil.parseInt(caMap[NUM_PLAYERS]);
            rdWeight_         = EncodeUtil.parseInt(caMap[RD_WEIGHT]);
            unitsBeforeDrain_ = EncodeUtil.parseInt(caMap[UNITS_BEFORE_DRAIN]);

            bin.nextTag(CPlayer.TAGS);
            if (bin.hasChildren())
            {
                bin.firstChild();
                while (!bin.reachedEndTag(CPlayer.TAGS))
                {
                    players_.Add(new CPlayer(bin));
                }
            }
            bin.endTag(CPlayer.TAGS);

            bin.nextTag(SPOTU);
            if (bin.hasChildren())
            {
                bin.firstChild();
                while (!bin.reachedEndTag(SPOTU))
                {
                    CUnit u = CUnit.decodeCUnit(bin, query_);
                    masterObjects_.Add(u.gid_, u);
                    spotMap_.Add(u.gid_, u);
                    spots_.Add(u);
                }
            }
            bin.endTag(SPOTU);


            bin.nextTag(SPOTC);
            if (bin.hasChildren())
            {
                bin.firstChild();
                while (!bin.reachedEndTag(SPOTC))
                {
                    CProducerUnit c = CProducerUnit.decodeCProducerUnit(bin, query_);
                    masterObjects_.Add(c.gid_, c);
                    knownCitiesVec_.Add(c);
                    spotMap_.Add(c.gid_, c);
                    spots_.Add(c);
                }
            }
            bin.endTag(SPOTC);

            bin.nextTag(SPOTP);
            if (bin.hasChildren())
            {
                bin.firstChild();
                while (!bin.reachedEndTag(SPOTP))
                {
                    CProducerUnit p = CProducerUnit.decodeCProducerUnit(bin, query);
                    masterObjects_.Add(p.gid_, p);
                    spotMap_.Add(p.gid_, p);
                    spots_.Add(p);
                }
            }
            bin.endTag(SPOTP);

            bin.nextTag(CITIES);
            if (bin.hasChildren())
            {
                bin.firstChild();
                while (!bin.reachedEndTag(CITIES))
                {
                    CProducerUnit c = CProducerUnit.decodeCProducerUnit(bin, query_);
                    masterObjects_.Add(c.gid_, c);
                    knownCitiesVec_.Add(c);
                    cities_.Add(c);
                    cityMap_.Add(c.gid_, c);
                }
            }
            bin.endTag(CITIES);


            bin.nextTag(UNITS);
            if (bin.hasChildren())
            {
                bin.firstChild();
                while (!bin.reachedEndTag(UNITS))
                {
                    CUnit u = CUnit.decodeCUnit(bin, query_);
                    masterObjects_.Add(u.gid_, u);
                    unitMap_.Add(u.gid_, u);
                    units_.Add(u);
                }
            }
            bin.endTag(UNITS);

            bin.nextTag(PRODUCERS);
            if (bin.hasChildren())
            {
                bin.firstChild();
                while (!bin.reachedEndTag(PRODUCERS))
                {
                    CProducerUnit p = CProducerUnit.decodeCProducerUnit(bin, query_);
                    masterObjects_.Add(p.gid_, p);
                    producers_.Add(p);
                    producerMap_.Add(p.gid_, p);
                    unitMap_.Add(p.gid_, p);
                    units_.Add(p);
                }
            }
            bin.endTag(PRODUCERS);

            bin.nextTag(CSupplyRoute.TAGS);
            if (bin.hasChildren())
            {
                bin.firstChild();
                while (!bin.reachedEndTag(CSupplyRoute.TAGS))
                {
                    var csr = new CSupplyRoute(bin);
                    supplySources_.Add(csr.rid_, csr);
                }
            }
            bin.endTag(CSupplyRoute.TAGS);

            map_     = new AIMap(bin);
            mapUtil_ = map_.mapUtil_;

            gameRules_ = new CGameRules(bin);

            vc_ = new CVictoryConditions(bin);

            bin.nextTag(CProposal.TAGS);
            if (bin.hasChildren())
            {
                bin.firstChild();
                while (!bin.reachedEndTag(CProposal.TAGS))
                {
                    var p = new CProposal(bin);
                    proposals_.Add(p);
                }
            }
            bin.endTag(CProposal.TAGS);

            bin.nextTag(CProductionReportData.TAGS);
            if (bin.hasChildren())
            {
                bin.firstChild();
                while (!bin.reachedEndTag(CProductionReportData.TAGS))
                {
                    var prd = new CProductionReportData(bin);
                    prodReport_.Add(prd);
                }
            }
            bin.endTag(CProductionReportData.TAGS);


            random_ = new CMTRandom(AI_RANDOM_TAG, bin);

            //retrieve flyover
            foUnit_ = null;
            if (caMap.ContainsKey(FOUNIT_ID))
            {
                uint fid = EncodeUtil.parseUInt(caMap[FOUNIT_ID]);
                foUnit_ = masterObjects_[fid];
            }
        }
コード例 #13
0
ファイル: CProducerUnit.cs プロジェクト: OlegYurchik/edce-ai
        public override bool update(string attr, string value, CSubLog logger)
        {
            if (base.update(attr, value, logger))
            {
                return(true);
            }

            switch (attr)
            {
            case CUnitConstants.PRODUCING:
                producing_ = value;
                return(true);

            case CUnitConstants.SPECIALTY:
            {
                specialty_ = value;
                return(true);
            }

            case CUnitConstants.EFFICIENCY:
            {
                efficiency_ = EncodeUtil.parseInt(value);
                return(true);
            }

            case CUnitConstants.TTC:
            {
                turnsToCompletion_ = EncodeUtil.parseInt(value);
                return(true);
            }

            case CUnitConstants.SUPPLY_STORE:
            {
                supplyStore_ = EncodeUtil.parseUInt(value);
                return(true);
            }

            case CUnitConstants.MIN_STORE:
            {
                minStore_ = EncodeUtil.parseUInt(value);
                return(true);
            }

            case CUnitConstants.SCRAPVAL:
            {
                scrapVal_ = EncodeUtil.parseUInt(value);
                return(true);
            }

            case CUnitConstants.AUTOSUPPLYDRAIN:
            {
                autoDrainSupply_ = EncodeUtil.fromBoolString(value);
                return(true);
            }

            case CUnitConstants.CONS_FOR_DRAIN:
            {
                consumeSupplyForDrain_ = EncodeUtil.fromBoolString(value);
                return(true);
            }

            case CUnitConstants.CONS_PRIORITY:
            {
                consumePriority_ = EncodeUtil.parseInt(value);
                return(true);
            }
            }



            return(false);
        }
コード例 #14
0
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        //Event Handler
        public override void processEvent(CGameEvent ge, CSubLog logger)
        {
            if (aiLogging_)
            {
                dlogger_.info("Event: " + ge.type_);
            }

            if (ge.type_ == CEventConstants.CONTINUETURNEVENT ||
                ge.type_ == CEventConstants.ENDTURN ||
                ge.type_ == CEventConstants.TURNCHANGE ||
                ge.type_ == CEventConstants.CHAT_EVENT)
            {
                return;
            }



            if (ge.type_ == CEventConstants.GAMSESTATE)
            {
                processGameState((CStateEvent)ge);
                return;
            }
            if (ge.type_ == CEventConstants.STARTTURNEVENT)
            {
                processStartTurn((CStartTurn)ge, logger);
                return;
            }

            //data updates
            if (ge.type_ == CEventConstants.PLAYERNAMECHANGE)
            {
                CPlayer cp = players_[ge.value1_];
                cp.pname_ = ge.info1_;
                return;
            }
            if (ge.type_ == CEventConstants.DRAIN_EVENT)
            {
                unitsBeforeDrain_ = ge.value1_;
                rdWeight_         = ge.value2_;
                return;
            }
            if (ge.type_ == CEventConstants.UNITUPDATE)
            {
                updateUnit(ge.cUpdate_, logger);
                return;
            }
            if (ge.type_ == CEventConstants.DEATHEVENT)
            {
                dlogger_.info("DEATH " + ge.gid_ + " " + ge.info1_);
                removeObject(ge.gid_);
                return;
            }
            if (ge.type_ == CEventConstants.FLYOVEREVENT)
            {
                if (ge.flag_)
                {
                    foUnit_ = getUnit(ge.gid_);
                }
                else
                {
                    foUnit_ = null;
                }
                return;
            }
            if (ge.type_ == CEventConstants.MAPLOCATION)
            {
                addMapLocation(ge.locInfo_);
                return;
            }
            if (ge.type_ == CEventConstants.NEWUNIT)
            {
                addObject(ge.unit_);
                return;
            }
            if (ge.type_ == CEventConstants.STOPTURNEVENT)
            {
                setHold();
                return;
            }
            if (ge.type_ == CEventConstants.SPOTTER)
            {
                return;
            }
            if (ge.type_ == CEventConstants.PLAYERDEAD)
            {
                players_[ge.value1_].living_ = false;
                if (ge.value1_ == position_)
                {
                    setHold();
                }
                return;
            }
            if (ge.type_ == CEventConstants.PLAYERWIN)
            {
                setHold();
                return;
            }
            if (ge.type_ == CEventConstants.END_OF_EVENTS)
            {
                setHold();
                return;
            }
            if (ge.type_ == CEventConstants.REMOVE_SUPPLY_EVENT)
            {
                supplySources_.Remove(ge.gid_);
                return;
            }
            if (ge.type_ == CEventConstants.SUPPLY_EVENT)
            {
                CSupplyRoute csr = ge.supplyRoute_;
                if (supplySources_.ContainsKey(csr.rid_))
                {
                    supplySources_[csr.rid_] = csr;
                }
                else
                {
                    supplySources_.Add(csr.rid_, csr);
                }
                return;
            }
            if (ge.type_ == CEventConstants.PLY_BUYPOINT_EVENT)
            {
                players_[position_].buypoints_      = ge.value1_;
                players_[position_].buypointsSpent_ = ge.value2_;
                return;
            }
            if (ge.type_ == CEventConstants.SCORE_EVENT)
            {
                players_[ge.value1_].score_ = ge.value2_;
            }
        }
コード例 #15
0
        public override void processEvent(CGameEvent ge, CSubLog logger)
        {
            base.processEvent(ge, logger);

            elogger_.info("Got Event:" + ge.type_);
        }
コード例 #16
0
ファイル: LoopCheck.cs プロジェクト: OlegYurchik/edce-ai
 public LoopCheck(int checkCount, CSubLog logger)
 {
     checkCount_ = checkCount;
     logger_     = logger;
 }
コード例 #17
0
ファイル: CUnit.cs プロジェクト: OlegYurchik/edce-ai
        public virtual bool update(string attr, string value, CSubLog logger)
        {
            switch (attr)
            {
            case CUnitConstants.NAME:
            {
                name_ = value;
                return(true);
            }

            case CUnitConstants.TURN:
            {
                turn_ = EncodeUtil.parseInt(value);
                return(true);
            }

            case CUnitConstants.HOST:
            {
                host_ = EncodeUtil.parseUInt(value);
                logger.info(this + " now has host value [" + Convert.ToString(host_) + "]");

                return(true);
            }

            case CUnitConstants.RMVR:
            {
                rmvr_ = EncodeUtil.parseInt(value);
                return(true);
            }

            case CUnitConstants.RMVS:
            {
                rmvs_ = EncodeUtil.parseInt(value);
                return(true);
            }

            case CUnitConstants.FIRED:
            {
                fired_ = EncodeUtil.fromBoolString(value);
                return(true);
            }

            case CUnitConstants.ARMED:
            {
                armed_ = EncodeUtil.fromBoolString(value);
                return(true);
            }

            case CUnitConstants.DUGIN:
            {
                dugIn_ = EncodeUtil.fromBoolString(value);
                return(true);
            }

            case CUnitConstants.DMG:
            {
                dmg_ = EncodeUtil.parseInt(value);
                return(true);
            }

            case CUnitConstants.SHORT_FUEL:
            {
                shortFuel_ = EncodeUtil.fromBoolString(value);
                return(true);
            }

            case CUnitConstants.READINESS:
            {
                readiness_ = value;
                return(true);
            }

            case CUnitConstants.EXPERIENCE:
            {
                experience_ = EncodeUtil.parseUInt(value);
                return(true);
            }

            case CUnitConstants.EXP_LEVEL:
            {
                expType_ = value;
                return(true);
            }

            case CUnitConstants.CHILD_ADD:
            {
                uint cgid = EncodeUtil.parseUInt(value);
                cunits_.Add(cgid);
                logger.info("Unit " + Convert.ToString(gid_) + " adds child " + Convert.ToString(cgid));
                return(true);
            }

            case CUnitConstants.CHILD_REM:
            {
                uint cgid = EncodeUtil.parseUInt(value);
                for (int j = 0; j < cunits_.Count; j++)
                {
                    if (cunits_[j] == cgid)
                    {
                        cunits_.RemoveAt(j);
                        break;
                    }
                }
                logger.info("Unit " + Convert.ToString(gid_) + " removes child " + Convert.ToString(cgid));
                return(true);
            }

            case CUnitConstants.LX:
                setLoc(new CLoc(EncodeUtil.parseInt(value), loc_.y));
                return(true);

            case CUnitConstants.LY:
                setLoc(new CLoc(loc_.x, EncodeUtil.parseInt(value)));
                return(true);

            case CUnitConstants.OWNER:     //will need to do more here if interested in gifts or giveaways
            {
                owner_ = EncodeUtil.parseInt(value);
                return(true);
            }

            case CUnitConstants.LANDED:
            {
                landed_ = EncodeUtil.fromBoolString(value);
                return(true);
            }

            case CUnitConstants.REENTRY:
            {
                inReentry_ = EncodeUtil.fromBoolString(value);
                return(true);
            }

            case CUnitConstants.LEVEL:
            {
                level_ = value;
                return(true);
            }

            case CUnitConstants.SLAYER:
            {
                stackLayer_ = EncodeUtil.parseUInt(value);
                return(true);
            }
            }
            return(false);
        }