/*********************************************************************/ /* */ /* マルチエージェントシミュレータ Version 1.0 */ /* */ /*********************************************************************/ //------------------ コンポーネントツリー --------------- WORLD { agent STATES(10,10)[0] { dim STATEID(10,10) AS Integer = (0); dim COLOR(10,10) AS Integer = (0); dim POWER(10,10) AS Double = (0.000000); dim FLG(10,10) AS Double = (0.000000); dim MISPERCEPTION(10,10)[1000] AS Double = (1000 * 0.000000); dim LAND_NUM(10,10) AS Integer = (0); } agent TERRITORY_UNIT(10,10)[0] { dim UNITID(10,10) AS Integer = (0); } space INTERNATIONAL_SYSTEM(10,10),HEXAGON_2D(38, 41, !LOOP) { agent TERRITORY(10,10)[0] { dim X(10,10) AS Double = (0.000000); dim Y(100,10) AS Double = (0.000000); dim DIRECTION(190,10) AS Double = (0.000000); dim COLOR(10,10) AS Integer = (0); dim STATEID(10,10) AS Integer = (0); dim LANDPOWER(10,10) AS Double = (0.000000); dim TRYID(10,10) AS Integer = (0); dim UNITID(10,10) AS Integer = (0); dim UNITANNEX(10,10) AS Integer = (0); } } dim INITIALPOWER_AVG(10,10) AS Double = (0.000000); dim INITIALPOWER_STDV(10,10) AS Double = (0.000000); dim MISPERCEPTION_AVG(10,10) AS Double = (0.000000); dim MISPERCEPTION_STDV(10,10) AS Double = (0.000000); dim FLG(10,10) AS Double = (0.000000); dim INITSRDSTS(10,10) AS Collection = (0); dim TARGET(10,10) AS Object = (0); dim INITIATOR(10,10) AS Object = (0); dim TARGETSRDSTS(10,10) AS Integer = (0); dim INITALLIANCE(10,10) AS Collection = (0); dim TARGETALLIANCE(10,10) AS Collection = (0); dim BASIC_WARCOST(10,10) AS Double = (0.000000); dim RESHUFFLE(10,10) AS Integer = (0); dim TURN(10,10) AS Integer = (0); dim REPARATIONS(10,10) AS Double = (0.000000); dim HARVEST(10,10) AS Double = (0.000000); dim IDENTIFICATION(10,10) AS Integer = (0); dim CONTINGENCY_STDV(10,10) AS Double = (0.000000); dim BELLICOSITY(10,10) AS Integer = (0); dim BALANCERFLG(10,10) AS Integer = (0); dim BALANCER(10,10) AS Object = (0); dim STNUM(10,10) AS Integer = (0); dim UNITANNEX_NUM(10,10) AS Integer = (0); } //------------------ コンポーネントパレットツリー --------------- //------------------ エージェント変数初期値データ --------------- INITIAL_VALUE { WORLD.INITIALPOWER_AVG = 1(10.000000); WORLD.INITIALPOWER_STDV = 1(3.290000); WORLD.MISPERCEPTION_AVG = 1(1.000000); WORLD.MISPERCEPTION_STDV = 1(0.200000); WORLD.BASIC_WARCOST = 1(0.100000); WORLD.REPARATIONS = 1(0.100000); WORLD.HARVEST = 1(0.030000); WORLD.CONTINGENCY_STDV = 1(0.200000); } //------------------ エージェント共通ルール --------------- #begin_rule common_agent_rule // RGB値指定 Function RGB(red As Integer, green As Integer, blue As Integer) As Integer { Return(red * (256^2) + green * 256 + blue) } // 初期状態での国家への色の割り振り Function statecolor(nx As Integer, ny As Integer) As Integer { Dim i As Integer If (nx < 7) Then Return(RGB(204 - ny*10 , nx * 30 + ny*10 , 0 + ny*10)) Else Return(RGB(204 - (nx - 6) * 18 - ny * 12, 204 - ny * 12, 0 + ny * 12)) End If } // 一定範囲内でのランダム値の出力 Function randomvalue(minX As Integer, maxX As Integer) As Integer { Return(CInt((maxX - minX + 1)*Rnd()) + minX) } // 役割の色による表示 Sub rolecolor(st As Object, color As Integer) { Dim trycol As Collection Dim try As Object trycol = _CollectAgent(WORLD.INTERNATIONAL_SYSTEM.TERRITORY) for each try in trycol if try.STATEID == st.STATEID then try.color = color end if next try _CloseCollection(trycol) } // 周辺国を取得(自国を除く) Function srdst(st As Object) As Collection { Dim trycol As Collection Dim own_col As Collection Dim t_col As Collection Dim ard_col As Collection Dim try As Object Dim own_try As Object Dim copyt_col As Collection Dim t_stcol As Collection Dim stcol As Collection Dim ardseacol As Collection Dim t_st As Object trycol = _InitCollection() own_col = _InitCollection() t_col = _InitCollection() ard_col = _InitCollection() copyt_col = _InitCollection() t_stcol = _InitCollection() stcol = _InitCollection() trycol = _CollectAgent(WORLD.INTERNATIONAL_SYSTEM.TERRITORY) // 領土を取得 for each try in trycol if try.STATEID == st.STATEID then _AddCollection(own_col,try) end if next try // 隣接国リストの取得 for each own_try in own_col ard_col = _CollectAround(own_try.X,own_try.Y,1,WORLD.INTERNATIONAL_SYSTEM,WORLD.INTERNATIONAL_SYSTEM.TERRITORY) t_col = _MakeMergeCollection(t_col,ard_col) next own_try copyt_col = _CopyCollection(t_col) for each try in copyt_col if try.STATEID == st.STATEID then _RemoveCollection(t_col,try) end if next try stcol = _CollectAgent(WORLD.STATES) for each try in t_col for each t_st in stcol if try.STATEID == t_st.STATEID then if _GetCollectionEntry(t_stcol,t_st) == -1 then _AddCollection(t_stcol,t_st) break end if end if next t_st next try _CloseCollection(trycol) _CloseCollection(own_col) _CloseCollection(t_col) _CloseCollection(ard_col) _CloseCollection(copyt_col) _CloseCollection(stcol) return(t_stcol) _CloseCollection(t_stcol) } // 国家の持つ領土を取得 Function getterritory(t_obj As Object) As Collection { Dim col As Collection Dim rtn_col As Collection Dim obj As Object rtn_col = _InitCollection() col = _CollectAgent(WORLD.INTERNATIONAL_SYSTEM.TERRITORY) for each obj in col if obj.STATEID == t_obj.STATEID then _AddCollection(rtn_col,obj) end if next obj _CloseCollection(col) Return(rtn_col) } Function NotZeroRnd() As Double { Dim x As Double Do While(x == 0) x = Rnd() Loop Return(x) } #end_rule common_agent_rule //------------------ エージェントルール --------------- #begin_rule WORLD Agt_Init{ Dim i As Integer Dim j As Integer Dim k As Integer Dim ct As Integer Dim trynum As Integer Dim clr(5) As Integer Dim clrb As Integer Dim clrc As Integer Dim intran As Double Dim try As Object Dim tryunit As Object Dim st As Object Dim s_st As Object Dim stcol(10) As Collection Dim s_stcol As Collection // 初期化 WORLD.FLG = 0 trynum = 0 WORLD.TARGETALLIANCE = _InitCollection() WORLD.TARGETSRDSTS =_InitCollection() WORLD.INITSRDSTS = _InitCollection() WORLD.INITALLIANCE = _InitCollection() // 国家の生成 _OpenFileCSV("table.txt",1,1) for i = 0 to 27 for j = 0 to 2 clr(j) = CInt(_ReadFileCSV(1)) next j st = _CreateAgent(WORLD.STATES) st.STATEID = i st.COLOR = RGB(clr(0),clr(1),clr(2)) st.FLG = 0 next i _CloseFileCSV(1) // 領土の生成 stcol = _CollectAgent(WORLD.STATES) _OpenFileCSV("stateid.txt",1,1) for i = 0 to _GetWidthSpace(WORLD.INTERNATIONAL_SYSTEM) - 1 for j = 0 to _GetHeightSpace(WORLD.INTERNATIONAL_SYSTEM) - 1 try = _CreateAgent(WORLD.INTERNATIONAL_SYSTEM.TERRITORY) try.X = i try.Y = j try.STATEID = CInt(_ReadFileCSV(1)) try.TRYID = trynum trynum = trynum + 1 try.UNITID = -1 try.UNITANNEX = 0 for each st in stcol if try.STATEID == st.STATEID then try.COLOR = st.COLOR st.LAND_NUM = st.LAND_NUM + 1 if i >= 33 and j <= 15 then try.LANDPOWER = 0 else try.LANDPOWER = _Norminv(NotZeroRnd(), WORLD.INITIALPOWER_AVG,WORLD.INITIALPOWER_STDV) end if st.POWER = st.POWER + try.LANDPOWER break end if next st next j next i _CloseFileCSV(1) // バランサーの格納 for each st in stcol if st.STATEID == 3 then WORLD.BALANCER = st break end if next st stcol = _CollectAgent(WORLD.STATES) // 評価誤差の決定 if WORLD.IDENTIFICATION == 0 then for each st in stcol st.misperception(1) = _Norminv(NotZeroRnd(), WORLD.MISPERCEPTION_AVG,WORLD.MISPERCEPTION_STDV) for i = 2 to 27 st.MISPERCEPTION(i) = st.MISPERCEPTION(1) next i next st elseif WORLD.IDENTIFICATION == 1 then for each st in stcol for i = 1 to 27 st.misperception(i) = _Norminv(NotZeroRnd(), WORLD.MISPERCEPTION_AVG,WORLD.MISPERCEPTION_STDV) next i next st end if // 国家数のカウント WORLD.STNUM = _CountAgent(WORLD.STATES) - 1 // 飛び地チェック用の領土単位へのIDづけ for i = 0 to 49 tryunit = _CreateAgent(WORLD.TERRITORY_UNIT) tryunit.UNITID = i next i } Agt_Step{ // 終了確認 simulationend() // 飛び地が生じた場合の回避 if WORLD.FLG == -8 then phase8() end if // 動作フラグのカウントアップ WORLD.FLG = WORLD.FLG + 1 // <第1フェイズ:イニシエーターの決定> if WORLD.FLG == 1 then phase1() end if // <第8フェイズ:パワー収穫と初期化> if WORLD.FLG == 8 then phase8() end if // 終了条件(色変更) finalcolorchange() } // <第1フェイズ:イニシエーターの決定> Sub phase1() { Dim landstcol As Collection Dim seastcol As Collection Dim totalstcol As Collection Dim copytotalstcol As Collection Dim st As Object Dim obj As Object Dim initstid As Integer // イニシエーターをパワーによるウェイトをかけてランダム決定(イギリスは除外) initstid = 3 do while initstid ==3 st = selectinitiator() initstid = st.STATEID loop if st <> -1 then st.FLG = 2 WORLD.INITIATOR = st _AddCollection(WORLD.INITALLIANCE,st) rolecolor(st,COLOR_RED) // イニシエーター周辺国の取得 landstcol = srdst(st) copytotalstcol = _CopyCollection(landstcol) for each obj in copytotalstcol if obj.STATEID == 0 then _RemoveCollection(landstcol,obj) end if next obj /* // 海を周辺国に取得した場合の処理 for each obj in landstcol if obj.STATEID == 0 then seastcol = srdst(obj) end if next obj // 陸周辺国と海周辺国の統合 totalstcol = _MakeMergeCollection(landstcol,seastcol) copytotalstcol = _CopyCollection(totalstcol) for each obj in copytotalstcol if obj.STATEID == 0 or obj.STATEID == st.STATEID then _RemoveCollection(totalstcol,obj) end if next obj */ // イニシエーター周辺国の格納 for each obj in landstcol _AddCollection(WORLD.INITSRDSTS,obj) next obj end if } // イニシエーターの選択 Function selectinitiator() As Object { Dim i As Integer Dim totalpower As Double Dim linepower(50) As Double Dim initst As Double Dim st As Object Dim stcol As Collection Dim copystcol As Collection stcol = _CollectAgent(WORLD.STATES) // 海の除外 copystcol = _CopyCollection(stcol) for each st in copystcol if st.STATEID == 0 then _RemoveCollection(stcol,st) end if next st totalpower = 0 for i = 0 to 49 linepower(i) = 0 next i for each st in stcol totalpower = totalpower + st.POWER next st i = 1 for each st in stcol linepower(i) = linepower(i-1) + st.POWER/totalpower i = i + 1 next st initst = Rnd() for i = 1 to _CountCollection(stcol) - 1 if initst >= linepower(i-1) and initst < linepower(i) then break end if next i st = _GetObject(stcol,i-1) return(st) } // <第8フェイズ:パワー収穫と初期化> Sub phase8() { Dim col As Collection Dim t_col As Collection Dim st_col As Collection Dim s_stcol As Collection Dim srdcol(100) As Collection Dim obj As Object Dim t_obj As Object Dim st As Object Dim s_st As Object Dim suv_obj As Object Dim HARVEST_AVG_rate As Double Dim i As Integer // パワー収穫 if WORLD.FLG == 8 then HARVEST_AVG_rate = WORLD.HARVEST col = _CollectAgent(WORLD.INTERNATIONAL_SYSTEM.TERRITORY) st_col = _CollectAgent(WORLD.STATES) for each obj in col for each st in st_col if obj.STATEID == st.STATEID then st.POWER = st.POWER + HARVEST_AVG_rate * obj.LANDPOWER end if next st next obj end if // 初期化 col = _CollectAgent(WORLD.STATES) for each obj in col obj.LAND_NUM = 0 next obj col = _CollectAgent(WORLD.INTERNATIONAL_SYSTEM.TERRITORY) st_col = _CollectAgent(WORLD.STATES) for each obj in col for each st in st_col if obj.STATEID == st.STATEID then st.LAND_NUM = st.LAND_NUM + 1 end if next st next obj // 飛び地チェック用領土単位フラグの初期化 for each obj in col obj.UNITID = -1 next obj col = _CollectAgent(WORLD.STATES) for each obj in col if obj.LAND_NUM == 0 Then _KillAgent(obj) end if next obj col = _CollectAgent(WORLD.INTERNATIONAL_SYSTEM.TERRITORY) st_col = _CollectAgent(WORLD.STATES) for each obj in col for each st in st_col if obj.STATEID == st.STATEID then obj.COLOR = st.COLOR end if next st next obj // 国家数のカウント WORLD.STNUM = _CountAgent(WORLD.STATES) - 1 // 国家のフラグの初期化 col = _CollectAgent(WORLD.STATES) for each obj in col obj.FLG = 0 next obj // バランサーの格納 for each obj in col if obj.STATEID == 3 then WORLD.BALANCER = obj break end if next obj WORLD.INITIATOR = -1 WORLD.TARGET = -1 WORLD.FLG = 0 // コレクションの初期化 col = _CopyCollection(WORLD.INITSRDSTS) for each obj in col _RemoveCollection(WORLD.INITSRDSTS,obj) next obj col = _CopyCollection(WORLD.TARGETSRDSTS) for each obj in col _RemoveCollection(WORLD.TARGETSRDSTS,obj) next obj col = _CopyCollection(WORLD.INITALLIANCE) for each obj in col _RemoveCollection(WORLD.INITALLIANCE,obj) next obj col = _CopyCollection(WORLD.TARGETALLIANCE) for each obj in col _RemoveCollection(WORLD.TARGETALLIANCE,obj) next obj WORLD.INITIATOR = -1 WORLD.TARGET = -1 if WORLD.RESHUFFLE == 1 then perception_reshuffle() end if _CloseCollection(col) _CloseCollection(t_col) // ターン数 WORLD.TURN = WORLD.TURN + 1 } Sub perception_reshuffle() { Dim stcol As Collection Dim st As Object Dim stnum As Integer Dim i As Integer stcol = _CollectAgent(WORLD.STATES) stnum = _CountAgent(WORLD.STATES) if WORLD.IDENTIFICATION == false then for each st in stcol st.misperception(1) = _Norminv(NotZeroRnd(), WORLD.MISPERCEPTION_AVG,WORLD.MISPERCEPTION_STDV) for i = 2 to stnum st.MISPERCEPTION(i) = st.MISPERCEPTION(1) next i next st else for each st in stcol for i = 1 to stnum st.misperception(i) = _Norminv(NotZeroRnd(), WORLD.MISPERCEPTION_AVG,WORLD.MISPERCEPTION_STDV) next i next st end if _CloseCollection(stcol) } Sub simulationend() { Dim col As Collection Dim st_col As Collection Dim obj As Object Dim st As Object if WORLD.FLG == -1 then _ExitSimulationMsg("最終ターン = " & WORLD.TURN) end if } Sub finalcolorchange() { Dim col As Collection Dim st_col As Collection Dim obj As Object Dim st As Object st_col = _CollectAgent(WORLD.STATES) if _CountCollection(st_col) == 3 then st = _GetObject(st_col, 0) col = _CollectAgent(WORLD.INTERNATIONAL_SYSTEM.TERRITORY) for each obj in col obj.COLOR = st.COLOR next obj WORLD.FLG = -1 end if _CloseCollection(col) } #end_rule WORLD //------------------ エージェントルール --------------- #begin_rule WORLD.STATES Agt_Init{ } Agt_Step{ // 動作チェック if My.FLG == 0 then Goto EndPlay end if // <第2フェイズ:ターゲットの選択> if My.FLG == 2 and WORLD.FLG == 2 then phase2() end if // <第3フェイズ:ターゲットの対応> if My.FLG == 3 and WORLD.FLG == 3 then phase3() end if // <第4フェイズ:イニシエーターの対応> if My.FLG == 4 and WORLD.FLG == 4 then phase4() end if // <第5フェイズ:ターゲットの最終対応> if My.FLG == 5 and WORLD.FLG == 5 then phase5() end if // <第6フェイズ:イニシエーターの最終決断> if My.FLG == 6 and WORLD.FLG == 6 then phase6() end if // <第7フェイズ:戦争とその結果> if My.FLG == 7 and WORLD.FLG == 7 then phase7() end if EndPlay: } // <第2フェイズ:ターゲットの選択> Sub phase2() { Dim landstcol As Collection Dim seastcol As Collection Dim isrdcol As Collection Dim totalstcol As Collection Dim copytotalstcol As Collection Dim obj As Object Dim weakest As Object Dim a_obj As Object // 最弱国の取得 weakest = getweakest(WORLD.INITSRDSTS) // ターゲットの決定 if weakest == -1 then My.FLG = -2 else weakest.FLG = 3 WORLD.TARGET = weakest isrdcol = _CopyCollection(WORLD.INITSRDSTS) for each obj in isrdcol if obj.STATEID == weakest.STATEID then _RemoveCollection(WORLD.INITSRDSTS,obj) end if next obj _AddCollection(WORLD.TARGETALLIANCE,weakest) rolecolor(weakest,COLOR_GREEN) My.FLG = -2 // ターゲット周辺国の取得 landstcol = srdst(weakest) copytotalstcol = _CopyCollection(landstcol) for each obj in copytotalstcol if obj.STATEID == 0 then _RemoveCollection(landstcol,obj) end if next obj /* // 海を周辺国に取得した場合の処理 for each obj in landstcol if obj.STATEID == 0 then seastcol = srdst(obj) end if next obj // 陸周辺国と海周辺国の統合 totalstcol = _MakeMergeCollection(landstcol,seastcol) copytotalstcol = _CopyCollection(totalstcol) for each obj in copytotalstcol if obj.STATEID == 0 or obj.STATEID == weakest.STATEID then _RemoveCollection(totalstcol,obj) end if next obj */ // ターゲット周辺国の格納 for each a_obj in landstcol if a_obj <> WORLD.INITIATOR then _AddCollection(WORLD.TARGETSRDSTS,a_obj) end if next a_obj // _CloseCollection(col) end if } // 最弱国を取得 Function getweakest(t_col As Collection) As Object { Dim t_num As Integer Dim weakest As Object Dim obj As Object Dim i As Integer Dim pvdpower(2) As Double // 最弱国の取得 t_num = _CountCollection(t_col) if t_num == 1 then weakest = _GetObject(t_col, 0) if My.POWER< perceivedpower(weakest.POWER,My.MISPERCEPTION(weakest.STATEID)) then return(-1) else return(weakest) end if else weakest = _GetObject(t_col, 0) pvdpower(0) = perceivedpower(weakest.POWER,My.MISPERCEPTION(weakest.STATEID)) for i = 0 to t_num - 1 obj = _GetObject(t_col, i) pvdpower(1) = perceivedpower(obj.POWER,My.MISPERCEPTION(obj.STATEID)) if pvdpower(0) > pvdpower(1) then weakest = obj pvdpower(0) = pvdpower(1) end if next i if My.POWER < pvdpower(0) then return(-1) else return(weakest) end if end if } // <第3フェイズ:ターゲットの対応> Sub phase3() { Dim t_col As Collection Dim x_col As Collection Dim final_col As Collection Dim stcol As Collection Dim st As Object Dim t_obj As Object Dim obj As Object Dim tt_obj As Object Dim side As Integer Dim pvdpower As Double Dim alliancepower As Double obj = WORLD.INITIATOR pvdpower = perceivedpower(obj.POWER,My.MISPERCEPTION(obj.STATEID)) if My.POWER > pvdpower then if WORLD.BALANCERFLG == 0 then obj.FLG = 7 else side = balancerrole() if side == 0 then obj.FLG = 6 else obj.FLG = 7 end if end if else t_col = _CopyCollection(WORLD.INITSRDSTS) // 計算可能判定 calculatable(t_col) // 同盟国リストの形成・打診・回答 x_col = selectalliance(t_col,My,pvdpower) final_col = _InitCollection() for each tt_obj in x_col if participation(tt_obj,My,x_col,WORLD.INITALLIANCE) == true then _AddCollection(final_col,tt_obj) end if next tt_obj if _CountCollection(final_col) > 0 then // イニシエータを第4フェーズへ obj.FLG = 4 // 同盟国の色変更 for each t_obj in final_col _AddCollection(WORLD.TARGETALLIANCE,t_obj) _RemoveCollection(WORLD.INITSRDSTS,t_obj) if _GetCollectionEntry(WORLD.TARGETSRDSTS,t_obj) >= 0 then _RemoveCollection(WORLD.TARGETSRDSTS,t_obj) end if rolecolor(t_obj, COLOR_GREEN + 100) next t_obj else // 同盟国の選択不能 obj = WORLD.INITIATOR if WORLD.BALANCERFLG == 0 then obj.FLG = 7 else side =balancerrole() if side == 0 then obj.FLG = 6 else obj.FLG = 7 end if end if end if end if My.FLG = -3 _CloseCollection(t_col) _CloseCollection(x_col) } // <第4フェイズ:イニシエーターの対応> Sub phase4() { Dim t_col As Collection Dim x_col As Collection Dim ard_col As Collection Dim t_alliancecol As Collection Dim final_col As Collection Dim t_num As Integer Dim side As Integer Dim obj As Object Dim t_obj As Object Dim tt_obj As Object Dim ttt_obj As Object Dim pvdpower As Double Dim alliancepower As Double // ターゲット同盟国の取得 t_alliancecol = _CopyCollection(WORLD.TARGETALLIANCE) ttt_obj = WORLD.TARGET pvdpower = totalpower(t_alliancecol,My) if My.POWER > pvdpower then obj = WORLD.INITIATOR if WORLD.BALANCERFLG == 0 then obj.FLG = 7 else side = balancerrole() if side == 0 then obj.FLG = 6 elseif side == 1 then obj.FLG = 5 else obj.FLG = 7 end if end if else t_col = _CopyCollection(WORLD.TARGETSRDSTS) calculatable(t_col) // 同盟国リストの形成・打診・回答 x_col = selectalliance(t_col,My,pvdpower) final_col = _InitCollection() for each tt_obj in x_col if participation(tt_obj,My,x_col,WORLD.INITALLIANCE) == true then _AddCollection(final_col,tt_obj) end if next tt_obj if _CountCollection(final_col) > 0 Then alliancepower = My.POWER + totalpower(final_col,My) if alliancepower < pvdpower then obj = WORLD.INITIATOR obj.FLG = 8 else obj = WORLD.TARGET obj.FLG = 5 // 同盟国の色変更 for each t_obj in final_col _AddCollection(WORLD.INITALLIANCE,t_obj) _RemoveCollection(WORLD.TARGETSRDSTS,t_obj) if _GetCollectionEntry(WORLD.INITSRDSTS,t_obj) >= 0 Then _RemoveCollection(WORLD.INITSRDSTS,t_obj) end if rolecolor(t_obj, COLOR_RED + 100) next t_obj end if else // 同盟国の選択不能 obj = WORLD.INITIATOR if WORLD.BALANCERFLG == 0 then obj.FLG = 8 else side = balancerrole() if side == 0 or side == -1 then obj.FLG = 8 else obj.FLG = 5 end if end if end if end if My.FLG = -4 _CloseCollection(t_col) } // <第5フェイズ:ターゲットの最終対応> Sub phase5() { Dim t_col As Collection Dim x_col As Collection Dim t_alliancecol As Collection Dim i_alliancecol As Collection Dim final_col As Collection Dim obj As Object Dim ttt_obj As Object Dim tt_obj As Object Dim st As Object Dim balancer As Integer Dim side As Integer Dim pvdpower As Double Dim alliancepower As Double ttt_obj = WORLD.TARGET obj = WORLD.INITIATOR // イニシエーター同盟国の取得 i_alliancecol = _CopyCollection(WORLD.INITALLIANCE) pvdpower = totalpower(i_alliancecol,My) // ターゲット同盟国の取得 t_alliancecol = _CopyCollection(WORLD.TARGETALLIANCE) alliancepower = totalpower(t_alliancecol,My) // バランサーがすでにイニシエーター同盟国になっているかどうかの確認 balancer = -1 for each st in i_alliancecol if st.STATEID == 3 then balancer = 1 break else balancer = 0 end if next st if balancer == 1 or WORLD.BALANCERFLG == 0 then if alliancepower > pvdpower then obj.FLG = 7 else t_col = _CopyCollection(WORLD.INITSRDSTS) calculatable(t_col) // 同盟国リストの形成・打診・回答 x_col = selectalliance(t_col,My,pvdpower) final_col = _InitCollection() for each tt_obj in x_col if participation(tt_obj,My,x_col,WORLD.INITALLIANCE) == true then _AddCollection(final_col,tt_obj) end if next tt_obj if _CountCollection(final_col) > 0 then // イニシエーターを第6フェーズへ obj.FLG = 6 // 同盟国の色変更 for each t_obj in final_col _AddCollection(WORLD.TARGETALLIANCE,t_obj) _RemoveCollection(WORLD.INITSRDSTS,t_obj) if _GetCollectionEntry(WORLD.TARGETSRDSTS,t_obj) > 0 Then _RemoveCollection(WORLD.TARGETSRDSTS,t_obj) end if rolecolor(t_obj,COLOR_GREEN + 200) next t_obj else // 同盟国の選択不能 obj = WORLD.INITIATOR obj.FLG = 7 end If end if else if alliancepower > pvdpower then side = balancerrole() if side == 0 then obj.FLG = 6 else obj.FLG = 7 end if else t_col = _CopyCollection(WORLD.INITSRDSTS) calculatable(t_col) // 同盟国リストの形成・打診・回答 x_col = selectalliance(t_col,My,pvdpower) final_col = _InitCollection() for each tt_obj in x_col if participation(tt_obj,My,x_col,WORLD.INITALLIANCE) == true then _AddCollection(final_col,tt_obj) end if next tt_obj if _CountCollection(final_col) > 0 then // イニシエーターを第6フェーズへ obj.FLG = 6 // 同盟国の色変更 for each t_obj in final_col _AddCollection(WORLD.TARGETALLIANCE,t_obj) _RemoveCollection(WORLD.INITSRDSTS,t_obj) if _GetCollectionEntry(WORLD.TARGETSRDSTS,t_obj) > 0 Then _RemoveCollection(WORLD.TARGETSRDSTS,t_obj) end if rolecolor(t_obj,COLOR_GREEN + 200) next t_obj else // 同盟国の選択不能 obj = WORLD.INITIATOR side = balancerrole() if side == 0 then obj.FLG = 6 else obj.FLG = 7 end if end if end if end if My.FLG = -5 } // <第6フェイズ:イニシエーターの最終決断> Sub phase6() { Dim t_alliancecol As Collection Dim i_alliancecol As Collection Dim total_alliancecol As Collection Dim st As Object Dim balancer As Integer Dim side As Integer Dim pvdpower As Double Dim alliancepower As Double // バランサーがどちらかの同盟国になっていないかの確認 t_alliancecol = _CopyCollection(WORLD.TARGETALLIANCE) i_alliancecol = _CopyCollection(WORLD.INITALLIANCE) total_alliancecol = _MakeMergeCollection(t_alliancecol,i_alliancecol) balancer = -1 for each st in total_alliancecol if st.STATEID == 3 then balancer = 1 break else balancer = 0 end if next st if WORLD.bellicosity == 0 then // ターゲット同盟国の取得 pvdpower = totalpower(t_alliancecol,My) // イニシエーター同盟国の取得 alliancepower = totalpower(i_alliancecol,My) if balancer == 0 and WORLD.BALANCERFLG == 1 then if pvdpower < alliancepower then side = balancerrole() if side == 0 then subphase6(My) else My.FLG = 7 end if else My.FLG = 8 end if else // 戦争の決定 if pvdpower < alliancepower then My.FLG = 7 else My.FLG = 8 end if end if else // リスク愛好型国家のために、戦争は避けられないが、開戦直前にバランサーは弱いと判断した方に同盟する if WORLD.BALANCERFLG == 1 then if balancer == 0 then side = balancerrole() end if end if My.FLG = 7 end if } // <第7フェイズ:戦争とその結果> Sub phase7() { Dim i_alliancecol As Collection Dim t_alliancecol As Collection Dim t_col As Collection Dim tt_col As Collection Dim i_col As Collection Dim it_col As Collection Dim obj As Object Dim init_st As Object Dim t_st As Object Dim i_num As Double Dim t_num As Double Dim war_costrate As Double Dim powerbalance As Double Dim cntcy As Double Dim icolpower As Double Dim t_alliancepower As Double Dim totalrep As Double Dim i_coltotalpower As Double Dim t_coltotalpower As Double init_st = WORLD.INITIATOR t_st = WORLD.TARGET // イニシエーター同盟国の取得 i_alliancecol = _CopyCollection(WORLD.INITALLIANCE) icolpower = totalpower2(i_alliancecol) // ターゲット同盟国の取得 t_alliancecol = _CopyCollection(WORLD.TARGETALLIANCE) t_alliancepower = totalpower2(t_alliancecol) powerbalance = icolpower / (icolpower + t_alliancepower) war_costrate = ( 1 - (powerbalance - 0.5) / 0.5 ) * WORLD.BASIC_WARCOST // 偶然性の加味 cntcy = _Norminv(NotZeroRND(),1,WORLD.CONTINGENCY_STDV) icolpower = icolpower * cntcy if icolpower > t_alliancepower then // 割譲する土地数 t_col = getterritory(t_st) t_num = powerbalance * _CountCollection(t_col) if t_num - CInt(t_num) > 0 then t_num = CInt(t_num) + 1 else t_num = CInt(t_num) end if if t_num >= _CountCollection(t_col) or t_num == 1 then // 全ての領土を割譲 tt_col = _CollectAgent(WORLD.INTERNATIONAL_SYSTEM.TERRITORY) for each obj in tt_col if obj.STATEID == t_st.STATEID then obj.STATEID = init_st.STATEID end if next obj // 戦争コスト・賠償金 totalrep = 0 i_coltotalpower = 0 for each obj in t_alliancecol totalrep = totalrep + obj.POWER*WORLD.reparations obj.POWER = obj.POWER - obj.POWER * war_costrate - obj.POWER * WORLD.reparations next obj for each obj in i_alliancecol i_coltotalpower = i_coltotalpower + obj.POWER next obj for each obj in i_alliancecol obj.POWER = obj.POWER - obj.POWER * war_costrate + totalrep*(obj.POWER/i_coltotalpower) next obj else // 一部の領土を割譲 partialconcession(init_st,t_st,t_num) // 戦争コストと賠償金 totalrep = 0 i_coltotalpower = 0 for each obj in t_alliancecol totalrep = totalrep + obj.POWER*WORLD.reparations obj.POWER = obj.POWER - obj.POWER * war_costrate - obj.POWER * WORLD.reparations next obj for each obj in i_alliancecol i_coltotalpower = i_coltotalpower + obj.POWER next obj for each obj in i_alliancecol obj.POWER = obj.POWER - obj.POWER * war_costrate + totalrep*(obj.POWER/i_coltotalpower) next obj end if else // 割譲する土地数 i_col = getterritory(init_st) i_num = powerbalance * _CountCollection(i_col) if i_num - CInt(i_num) > 0 then i_num = CInt(i_num) + 1 else i_num = CInt(i_num) end if if i_num >= _CountCollection(i_col) or i_num == 1 then // 全ての領土を割譲 it_col = _CollectAgent(WORLD.INTERNATIONAL_SYSTEM.TERRITORY) for each obj in it_col if obj.STATEID == init_st.STATEID then obj.STATEID = t_st.STATEID end if next obj // 戦争コスト・賠償金 totalrep = 0 t_coltotalpower = 0 for each obj in i_alliancecol totalrep = totalrep + obj.POWER*WORLD.reparations obj.POWER = obj.POWER - obj.POWER * war_costrate - obj.POWER * WORLD.reparations next obj for each obj in t_alliancecol t_coltotalpower = t_coltotalpower + obj.POWER next obj for each obj in i_alliancecol obj.POWER = obj.POWER - obj.POWER * war_costrate + totalrep*(obj.POWER/t_coltotalpower) next obj else // 一部の領土を割譲 partialconcession(t_st,init_st,i_num) // 戦争コストと賠償金 totalrep = 0 t_coltotalpower = 0 for each obj in i_alliancecol totalrep = totalrep + obj.POWER*WORLD.reparations obj.POWER = obj.POWER - obj.POWER * war_costrate - obj.POWER * WORLD.reparations next obj for each obj in t_alliancecol t_coltotalpower = t_coltotalpower + obj.POWER next obj for each obj in t_alliancecol obj.POWER = obj.POWER - obj.POWER * war_costrate + totalrep*(obj.POWER/t_coltotalpower) next obj end if end if endstep: _CloseCollection(i_alliancecol) _CloseCollection(t_alliancecol) _CloseCollection(t_col) } // 認知されたパワーの算出 Function perceivedpower(power As Double, mispv As Double) As Double { Return(mispv * power) } Sub calculatable(t_col As Collection) { Dim t_num As Integer // 隣接国の数を算出 t_num = _CountCollection(t_col) // 計算可能判定 If t_num > 31 Then _ExitSimulationMsg("caluculation is impossible") End If } //同盟国の評価されたパワーの総和 Function totalpower(t_col As Collection,m_obj As Object) As Double { Dim alliancepower As Double Dim t_num As Integer Dim obj As Object Dim i As Integer t_num = _CountCollection(t_col) if t_num == 0 then return(0.0) end if alliancepower = 0.0 if t_num == 1 then obj = _GetObject(t_col, 0) if obj.STATEID == m_obj.STATEID then alliancepower = obj.POWER else alliancepower = perceivedpower(obj.POWER,m_obj.MISPERCEPTION(obj.STATEID)) end if else for each obj in t_col if obj.STATEID == m_obj.STATEID then alliancepower = alliancepower + obj.POWER else alliancepower = alliancepower + perceivedpower(obj.POWER,m_obj.MISPERCEPTION(obj.STATEID)) end if next obj end if return(alliancepower) } // 同盟国の真のパワーの総和 Function totalpower2(t_col As Collection) As Double { Dim alliancepower As Double Dim t_num As Integer Dim obj As Object Dim i As Integer t_num = _CountCollection(t_col) if t_num == 0 then return(0.0) end if alliancepower = 0.0 if t_num == 1 then obj = _GetObject(t_col, 0) alliancepower = obj.POWER else for i = 0 To t_num - 1 obj = _GetObject(t_col, i) alliancepower = alliancepower + obj.POWER next i end if return(alliancepower) } Function selectalliance(t_col As Collection, my_obj As Object, ppwer As Double) As Collection { Dim rtn_col As Collection Dim obj As Object Dim t_num As Integer Dim powerdif As Double DIm minpowerdif As Double Dim allyflg As Integer Dim minallyflg As Integer Dim allyp As Double Dim i As Integer Dim ct As Integer Dim res As Integer rtn_col = _InitCollection() // 隣接国の数を算出 t_num = _CountCollection(t_col) // 同盟国の選択 if t_num == 1 then obj = _GetObject(t_col,0) allyp = my_obj.POWER + perceivedpower(obj.POWER,my_obj.MISPERCEPTION(obj.STATEID)) powerdif = allyp - ppwer if powerdif > 0 then _AddCollection(rtn_col,obj) end if else // 同盟国フラグ:二進数にて組合せを選択 minallyflg = 2 ^ t_num - 1 minpowerdif = (my_obj.POWER + totalpower(t_col,my_obj)) - ppwer for i = 1 to (2 ^ t_num - 1) allyflg = i allyp = my_obj.POWER ct = 0 do while(1) res = allyflg Mod 2 if res == 1 then obj = _GetObject(t_col,ct) allyp = allyp + perceivedpower(obj.POWER,my_obj.MISPERCEPTION(obj.STATEID)) end if allyflg = (allyflg - res) / 2 ct = ct + 1 if allyflg < 2 then break end if loop powerdif = allyp - ppwer if (powerdif > 0) and (powerdif < minpowerdif) then minpowerdif = powerdif minallyflg = i end if next i // 同盟国のフラグ変更 allyflg = minallyflg ct = 0 do while(1) res = allyflg Mod 2 obj = _GetObject(t_col, ct) if res == 1 then _AddCollection(rtn_col, obj) end if allyflg = (allyflg - res) / 2 ct = ct + 1 if allyflg < 2 then break end if loop end if return(rtn_col) } // 打診された同盟に参加するか否かの決定 Function participation(tt_obj As Object,m_obj As Object,x_col As Collection,initalcol As Collection) As Boolean { Dim m_totalpower As Double Dim e_totalpower As Double Dim xx_col As Collection Dim mm_obj As Object Dim bl As Boolean xx_col = _CopyCollection(x_col) for each mm_obj in x_col if mm_obj == tt_obj then _RemoveCollection(xx_col,mm_obj) break end if next mm_obj _AddCollection(xx_col,m_obj) m_totalpower = tt_obj.POWER + totalpower(xx_col,tt_obj) e_totalpower = totalpower(initalcol,tt_obj) if m_totalpower > e_totalpower then bl = true return(bl) else bl = false return(bl) end if } Function getborder(c_col As Collection) As Collection { Dim col As Collection Dim ard_col As Collection Dim rtn_col As Collection Dim k_col As Collection Dim obj As Object Dim c_obj As Object Dim ard_obj As Object Dim x_col As Collection rtn_col = _InitCollection() x_col = _InitCollection() If _CountCollection(c_col) == 1 Then c_obj = _GetObject(c_col,0) rtn_col = _CollectAround(c_obj.X,c_obj.Y,1,WORLD.INTERNATIONAL_SYSTEM,WORLD.INTERNATIONAL_SYSTEM.TERRITORY) Return(rtn_col) Else For Each c_obj In c_col ard_col = _CollectAround(c_obj.X,c_obj.Y,1,WORLD.INTERNATIONAL_SYSTEM,WORLD.INTERNATIONAL_SYSTEM.TERRITORY) x_col = _MakeMergeCollection(rtn_col,ard_col) rtn_col = _CopyCollection(x_col) Next c_obj End If // コアの確認 rtn_col = _MakeDelCollection(rtn_col,c_col) Return(rtn_col) } Sub partialconcession(a_obj As Object, b_obj As Object, c_num As Integer) { Dim a_col As Collection Dim b_col As Collection Dim bordera_col As Collection Dim commoncol As Collection Dim copycommoncol As Collection Dim connectcol As Collection Dim mincol As Collection Dim trycol As Collection Dim backupcol As Collection Dim loopavoidancecol As Collection Dim ecol As Collection Dim tryunitcol As Collection Dim tryobj As Object Dim obj As Object Dim etry As Object Dim tryunit As Object Dim n As Integer Dim commoncolnum As Integer Dim commoncolcheck As Integer Dim objcheck As Integer Dim rtn As Integer backupcol = _InitCollection() do while(1) if c_num == 0 then Goto EndLoop end if a_col = getterritory(a_obj) b_col = getterritory(b_obj) bordera_col = getborder(a_col) // 敗戦国盟主の領土のうち、戦勝国盟主に接する領土を取得 connectcol = _MakeMergeCollection(bordera_col,b_col) mincol = _MakeDiffCollection(bordera_col,b_col) commoncol = _MakeDelCollection(connectcol,mincol) n = _CountCollection(commoncol) commoncolnum = n loopavoidancecol = _MakeDiffCollection(commoncol,backupcol) if _CountCollection(loopavoidancecol) == 0 then goto EndLoop end if if n == 0 then Goto EndLoop end if if n == 1 then obj = _GetObject(commoncol,0) if checksplit(a_obj,b_col,obj,b_obj,c_num,commoncol) > 0 then // OK obj.STATEID = a_obj.STATEID end if c_num = c_num - 1 commoncolnum = commoncolnum - 1 // UNITIDとUNITANNEXの初期化 trycol = _CollectAgent(WORLD.INTERNATIONAL_SYSTEM.TERRITORY) for each tryobj in trycol tryobj.UNITID = -1 tryobj.UNITANNEX = 0 next tryobj Goto EndLoop else commoncolcheck = 0 do while(1) if _CountCollection(commoncol) == 0 then goto endsmall_loop end if copycommoncol = _CopyCollection(commoncol) // 無限ループの回避のためのコレクション backupcol = _InitCollection() for each obj in copycommoncol objcheck = _GetCollectionEntry(commoncol,obj) if objcheck >= 0 then if checksplit(a_obj,b_col,obj,b_obj,c_num,commoncol) > 0 then // OK _RemoveCollection(b_col,obj) obj.STATEID = a_obj.STATEID c_num = c_num - 1 commoncolnum = commoncolnum - 1 // 飛び地チェックで確認した領土単位全体での割譲 ecol = _CollectAgent(WORLD.INTERNATIONAL_SYSTEM.TERRITORY) for each etry in ecol if etry.UNITANNEX == 1 then _RemoveCollection(b_col,etry) if _GetCollectionEntry(commoncol,etry) >= 0 then _RemoveCollection(commoncol,etry) end if etry.STATEID = a_obj.STATEID end if next etry c_num = c_num - WORLD.UNITANNEX_NUM WORLD.UNITANNEX_NUM = 0 end if _RemoveCollection(commoncol,obj) _AddCollection(backupcol,obj) // UNITIDとUNITANNEXの初期化 trycol = _CollectAgent(WORLD.INTERNATIONAL_SYSTEM.TERRITORY) for each tryobj in trycol tryobj.UNITID = -1 tryobj.UNITANNEX = 0 next tryobj if c_num == 0 then Goto EndLoop end if end if next obj loop endsmall_loop: end if loop EndLoop: _CloseCollection(a_col) _CloseCollection(b_col) _CloseCollection(bordera_col) _CloseCollection(commoncol) } // 飛び地回避の確認 Function checksplit(a_obj As Object,b_col As Collection,obj As Object,b_obj As Object,c_num As Integer,commoncol As Collection) As Integer { Dim hypocol As Collection Dim ardcol As Collection Dim copyardcol As Collection Dim tunitcol As Collection Dim copytunitcol As Collection Dim c_col As Collection Dim d_col As Collection Dim borderc_col As Collection Dim connectcol As Collection Dim mincol As Collection Dim unitcommoncol As Collection Dim adjacent As Collection Dim adcheckcol As Collection Dim try As Object Dim checktry As Object Dim tunit As Object Dim cunit As Object Dim dunit As Object Dim eunit As Object Dim i As Integer Dim j As Integer Dim ct As Integer Dim unitobjnum As Integer Dim entrycheck As Integer Dim newcolflg As Integer Dim adjacentcheck As Integer Dim n As Integer Dim m As Integer Dim c_unit_num As Integer Dim rtn As Integer Dim testcol As Collection Dim testobj As Object Dim testint As Integer // 初期化 ct = 0 c_unit_num = 0 // 敗戦国盟主の領土の取得 hypocol = _CopyCollection(b_col) // 飛び地にしてしまうかをチェックしたい対象のへクスを敗戦国盟主から仮に割譲し、仮の割譲した状態を作成 _RemoveCollection(hypocol,obj) // 仮に領土を割譲した状態を想定して、飛び地になっていないかをチェック // チェックのための領土単位の形成 for each try in hypocol ardcol = _CollectAround(try.X,try.Y,1,WORLD.INTERNATIONAL_SYSTEM,WORLD.INTERNATIONAL_SYSTEM.TERRITORY) // 自国以外の領土の除外、try変数のへクスの除外、仮に割譲した領土の除外 copyardcol = _CopyCollection(ardcol) for each checktry in copyardcol if checktry.STATEID <> b_obj.STATEID or checktry.TRYID == try.TRYID or checktry.TRYID == obj.TRYID then _RemoveCollection(ardcol,checktry) end if next checktry // tryへクスがどのTRYUNITにも入っていなかった場合の新規コレクションの形成 if try.UNITID == -1 then ct = ct + 1 c_unit_num = c_unit_num + 1 try.UNITID = ct end if // 周辺へクスの処理 for each checktry in ardcol // 周辺へクスがどのコレクションにも入っていない場合、tryへクスを入れた新規コレクションに追加 if checktry.UNITID == -1 then checktry.UNITID = try.UNITID end if next checktry next try tunitcol = _CollectAgent(WORLD.TERRITORY_UNIT) copytunitcol = _CopyCollection(tunitcol) // 領土単位が形成されなかったオブジェクトの削除 for each tunit in copytunitcol if tunit.UNITID == 0 or tunit.UNITID > ct then _RemoveCollection(tunitcol,tunit) end if next tunit copytunitcol = _CopyCollection(tunitcol) // 形成された領土単位のうち、割譲領土数よりも少なくかつ引数として指定してある領土に隣接している領土を割譲できるものとして取得 for each tunit in copytunitcol c_col = getunitterritory(tunit) unitobjnum = _CountCollection(c_col) if unitobjnum == 0 then _RemoveCollection(tunitcol,tunit) else adjacent = _CollectAround(obj.X,obj.Y,1,WORLD.INTERNATIONAL_SYSTEM,All) adcheckcol = _MakeCommonCollection(adjacent,c_col) adjacentcheck = _CountCollection(adcheckcol) if unitobjnum < c_num and adjacentcheck > 0 then for each eunit in c_col eunit.UNITANNEX = 1 next eunit _RemoveCollection(tunitcol,tunit) WORLD.UNITANNEX_NUM = 0 WORLD.UNITANNEX_NUM = unitobjnum c_unit_num = c_unit_num - 1 end if end if next tunit // 形成された領土単位のうち、単位全体を併合できなかった残りの単位について、すべての組み合わせで隣接しているかをチェック n = 1 if c_unit_num == 1 then rtn = 1 else do while n < ct cunit = -1 for each tunit in tunitcol if tunit.UNITID == n then cunit = tunit end if next tunit // 領土単位全体を削除可能とした単位のIDにカウンタがきたときの処理 if cunit == -1 then goto last end if m = n + 1 for i = m to ct dunit = -1 for each tunit in tunitcol if tunit.UNITID == i then dunit = tunit end if next tunit // 領土単位全体を削除可能とした単位のIDにカウンタがきたときの処理 if dunit == -1 then goto small_last end if c_col = getunitterritory(cunit) d_col = getunitterritory(dunit) borderc_col = getborder(c_col) // d_colの領土単位のうち、c_colに接する領土を取得 connectcol = _MakeMergeCollection(borderc_col,d_col) mincol = _MakeDiffCollection(borderc_col,d_col) unitcommoncol = _MakeDelCollection(connectcol,mincol) rtn = _CountCollection(unitcommoncol) if rtn == 0 then goto endloop end if small_last: next i last: n = n + 1 loop endloop: end if return(rtn) _CloseCollection(hypocol) _CloseCollection(ardcol) _CloseCollection(copyardcol) _CloseCollection(tunitcol) _CloseCollection(copytunitcol) _CloseCollection(c_col) _CloseCollection(d_col) _CloseCollection(borderc_col) _CloseCollection(connectcol) _CloseCollection(mincol) _CloseCollection(unitcommoncol) _CloseCollection(adjacent) _CloseCollection(adcheckcol) } // 飛び地チェック用領土単位に含まれる領土を取得 Function getunitterritory(t_obj As Object) As Collection { Dim col As Collection Dim rtn_col As Collection Dim obj As Object rtn_col = _InitCollection() col = _CollectAgent(WORLD.INTERNATIONAL_SYSTEM.TERRITORY) for each obj in col if obj.UNITID == t_obj.UNITID then _AddCollection(rtn_col,obj) end if next obj Return(rtn_col) _CloseCollection(rtn_col) } // バランサーがいる場合 Function balancerrole() As Integer { Dim balancer As Object Dim i_alliancecol As Collection Dim t_alliancecol As Collection Dim side As Integer Dim bipvdpower As Double Dim btpvdpower As Double balancer = WORLD.BALANCER i_alliancecol = _CopyCollection(WORLD.INITALLIANCE) t_alliancecol = _CopyCollection(WORLd.TARGETALLIANCE) side = -1 bipvdpower = totalpower(i_alliancecol,balancer) btpvdpower = totalpower(t_alliancecol,balancer) if bipvdpower > btpvdpower then _AddCollection(WORLD.TARGETALLIANCE,balancer) rolecolor(balancer,COLOR_GREEN) side = 0 elseif bipvdpower < btpvdpower then _AddCollection(WORLD.INITALLIANCE,balancer) rolecolor(balancer,COLOR_RED) side = 1 end if return(side) } // <第6フェイズ:イニシエーターの最終決断> Sub subphase6(init_obj As Object) { Dim t_alliancecol As Collection Dim i_alliancecol As Collection Dim pvdpower As Double Dim alliancepower As Double // ターゲット同盟国の取得 t_alliancecol = _CopyCollection(WORLD.TARGETALLIANCE) pvdpower = totalpower(t_alliancecol,init_obj) // イニシエーター同盟国の取得 i_alliancecol = _CopyCollection(WORLD.INITALLIANCE) alliancepower = totalpower(i_alliancecol,init_obj) // 戦争の決定 if pvdpower < alliancepower then init_obj.FLG = 7 else init_obj.FLG = 8 end if } #end_rule WORLD.STATES //------------------ エージェントルール --------------- #begin_rule WORLD.TERRITORY_UNIT Agt_Init{ } Agt_Step{ } #end_rule WORLD.TERRITORY_UNIT //------------------ エージェントルール --------------- #begin_rule WORLD.INTERNATIONAL_SYSTEM.TERRITORY Agt_Init{ } Agt_Step{ } #end_rule WORLD.INTERNATIONAL_SYSTEM.TERRITORY //------------------ コンポーネントメモ --------------- #begin_compo_memo WORLD.TERRITORY_UNIT #end_compo_memo WORLD.TERRITORY_UNIT //------------------ コンポーネントメモ --------------- #begin_compo_memo WORLD.INTERNATIONAL_SYSTEM.TERRITORY.UNITANNEX #end_compo_memo WORLD.INTERNATIONAL_SYSTEM.TERRITORY.UNITANNEX //------------------ シミュレーション設定部 --------------- SINGLE_SIMULATION { STEP_MAX = 0; TIME_MAX = 0; END_CONDITION = ""; EXEC_WAIT = 0; EXEC_ORDER = RANDOM; RANDOM_SEED = 0; LOG_FILE = "",SEREIAL_NO,OVERWRITE,0; } //------------------ ループ設定部 --------------- REPEAT_SIMULATION { VALUE_CHANGE = NONE; REPEAT_MAX = 1; VARIABLES = ""; START_VALUE = 0.000000; STEP_VALUE = 1.000000; END_VALUE = 1.000000; EXEC_TIMES_SAME = 1; RANDOM_RANGE = 0.000000, 1.000000; SAME_VALUE = YES; EXEC_TIMES_DIFFERENT = 1; } //------------------ 二次元マップ表示出力設定部 --------------- MAP_OUTPUT { MAP_SPACE_NAME = "WORLD.INTERNATIONAL_SYSTEM"; MAP_NAME = "International_System"; TITLE = "19世紀ヨーロッパ"; AXIS_LABEL = "", ""; DRAW_RANGE = 0, 0, 37, 40; RULED_LINE = NO; REMARKS = NO; SPACE_KIND = HEXAGON_2D; BG_PICT = NO; BG_TYPE = 0; BG_VAR_NAME = ""; BG_FILE_NAME = ""; DISABLE = NO; POSITION_X = 302; POSITION_Y = 12; SIZE_X = 942; SIZE_Y = 885; OUTPUT { MAP_ELEMENT_NAME = "領土"; MAP_ELEMENT = AGENT_VARIABLE; OUTPUT_EXPRESSION = "WORLD.INTERNATIONAL_SYSTEM.TERRITORY"; SPACE_DRAW_RANGE = 0.000000, 0.000000; SPACE_COLOR_MIN = 255,255,255; SPACE_COLOR_MAX = 0,0,255; AGENT_COLOR = "WORLD.INTERNATIONAL_SYSTEM.TERRITORY.COLOR"; MARKER_ID = 1; ICON_TYPE = 0; ICON_VAR_NAME = ""; ICON_FILE_NAME = ""; MAP_COLOR = 0,0,0; NUM_DISPLAY = YES; NUM_VAR_NAME = "WORLD.INTERNATIONAL_SYSTEM.TERRITORY.STATEID"; } } //------------------ 数値画面出力設定部 --------------- NUMERIC_OUTPUT { NUMERIC_NAME = "数値画面出力"; TITLE = "数値出力"; DISABLE = NO; POSITION_X = 3; POSITION_Y = 2; SIZE_X = 255; SIZE_Y = 229; OUTPUT { OUTPUT_ELEMENT_NAME = "ターン数"; FIGURES = 0; FORMAT_ID = 0; OUTPUT_EXPRESSION = "WORLD.TURN"; } OUTPUT { OUTPUT_ELEMENT_NAME = "国家数"; FIGURES = 0; FORMAT_ID = 78; OUTPUT_EXPRESSION = "WORLD.STNUM"; } } //------------------ 時系列グラフ出力設定部 --------------- TIME_GRAPH { GRAPH_NAME = "国家数"; TITLE = "国家数"; AXIS_LABEL = "ターン数(X軸はステップ数:1ターン=8ステップ)", "国家数"; SCALE = 0.000000, 0.000000, 8000.000000, 100.000000, 100.000000, 5.000000; REMARKS = NO; DISABLE = NO; POSITION_X = 4; POSITION_Y = 120; SIZE_X = 385; SIZE_Y = 208; OUTPUT { GRAPH_ELEMENT_NAME = "国家数"; LINE_COLOR = 64,255,0; LINE_WIDTH = 3; MARKER_ID = 0; OUTPUT_EXPRESSION = "WORLD.STNUM"; } } //------------------ コントロールパネルデータ設定部 --------------- CONTROL_PANEL { PANEL_ITEM { ITEM_NAME = "基本戦争コスト"; ITEM_TYPE = SLIDER; VAR_NAME = WORLD.BASIC_WARCOST; CONTROL_ON = NO; CONTROL_ON_INT = 0; CONTROL_ON_DOUBLE = 1.000000; CONTROL_ON_STRING = ""; CONTROL_OFF = NO; CONTROL_OFF_INT = 0; CONTROL_OFF_DOUBLE = 0.000000; CONTROL_OFF_STRING = ""; SLIDER_RANGE_MAX = 5; SLIDER_VALUE_MIN = 0.000000; SLIDER_VALUE_STEP = 0.100000; } PANEL_ITEM { ITEM_NAME = "パワー初期値:平均"; ITEM_TYPE = EDIT_BOX; VAR_NAME = WORLD.INITIALPOWER_AVG; CONTROL_ON = NO; CONTROL_ON_INT = 0; CONTROL_ON_DOUBLE = 1.000000; CONTROL_ON_STRING = ""; CONTROL_OFF = NO; CONTROL_OFF_INT = 0; CONTROL_OFF_DOUBLE = 0.000000; CONTROL_OFF_STRING = ""; SLIDER_RANGE_MAX = 1; SLIDER_VALUE_MIN = 0.000000; SLIDER_VALUE_STEP = 1.000000; } PANEL_ITEM { ITEM_NAME = "パワー初期値:標準偏差"; ITEM_TYPE = SLIDER; VAR_NAME = WORLD.INITIALPOWER_STDV; CONTROL_ON = NO; CONTROL_ON_INT = 0; CONTROL_ON_DOUBLE = 1.000000; CONTROL_ON_STRING = ""; CONTROL_OFF = NO; CONTROL_OFF_INT = 0; CONTROL_OFF_DOUBLE = 0.000000; CONTROL_OFF_STRING = ""; SLIDER_RANGE_MAX = 900; SLIDER_VALUE_MIN = 1.000000; SLIDER_VALUE_STEP = 0.010000; } PANEL_ITEM { ITEM_NAME = "評価誤差:平均"; ITEM_TYPE = EDIT_BOX; VAR_NAME = WORLD.MISPERCEPTION_AVG; CONTROL_ON = NO; CONTROL_ON_INT = 0; CONTROL_ON_DOUBLE = 1.000000; CONTROL_ON_STRING = ""; CONTROL_OFF = NO; CONTROL_OFF_INT = 0; CONTROL_OFF_DOUBLE = 0.000000; CONTROL_OFF_STRING = ""; SLIDER_RANGE_MAX = 1; SLIDER_VALUE_MIN = 0.000000; SLIDER_VALUE_STEP = 1.000000; } PANEL_ITEM { ITEM_NAME = "評価誤差:標準偏差"; ITEM_TYPE = SLIDER; VAR_NAME = WORLD.MISPERCEPTION_STDV; CONTROL_ON = NO; CONTROL_ON_INT = 0; CONTROL_ON_DOUBLE = 1.000000; CONTROL_ON_STRING = ""; CONTROL_OFF = NO; CONTROL_OFF_INT = 0; CONTROL_OFF_DOUBLE = 0.000000; CONTROL_OFF_STRING = ""; SLIDER_RANGE_MAX = 8; SLIDER_VALUE_MIN = 0.100000; SLIDER_VALUE_STEP = 0.050000; } PANEL_ITEM { ITEM_NAME = "評価誤差:更新"; ITEM_TYPE = TOGGLE; VAR_NAME = WORLD.RESHUFFLE; CONTROL_ON = NO; CONTROL_ON_INT = 1; CONTROL_ON_DOUBLE = 0.000000; CONTROL_ON_STRING = ""; CONTROL_OFF = NO; CONTROL_OFF_INT = 0; CONTROL_OFF_DOUBLE = 0.000000; CONTROL_OFF_STRING = ""; SLIDER_RANGE_MAX = 1; SLIDER_VALUE_MIN = 0.000000; SLIDER_VALUE_STEP = 1.000000; } PANEL_ITEM { ITEM_NAME = "評価誤差:識別"; ITEM_TYPE = TOGGLE; VAR_NAME = WORLD.IDENTIFICATION; CONTROL_ON = NO; CONTROL_ON_INT = 1; CONTROL_ON_DOUBLE = 0.000000; CONTROL_ON_STRING = ""; CONTROL_OFF = NO; CONTROL_OFF_INT = 0; CONTROL_OFF_DOUBLE = 0.000000; CONTROL_OFF_STRING = ""; SLIDER_RANGE_MAX = 1; SLIDER_VALUE_MIN = 0.000000; SLIDER_VALUE_STEP = 1.000000; } PANEL_ITEM { ITEM_NAME = "リスク愛好型"; ITEM_TYPE = TOGGLE; VAR_NAME = WORLD.BELLICOSITY; CONTROL_ON = NO; CONTROL_ON_INT = 1; CONTROL_ON_DOUBLE = 0.000000; CONTROL_ON_STRING = ""; CONTROL_OFF = NO; CONTROL_OFF_INT = 0; CONTROL_OFF_DOUBLE = 0.000000; CONTROL_OFF_STRING = ""; SLIDER_RANGE_MAX = 1; SLIDER_VALUE_MIN = 0.000000; SLIDER_VALUE_STEP = 1.000000; } PANEL_ITEM { ITEM_NAME = "賠償率"; ITEM_TYPE = SLIDER; VAR_NAME = WORLD.REPARATIONS; CONTROL_ON = NO; CONTROL_ON_INT = 0; CONTROL_ON_DOUBLE = 1.000000; CONTROL_ON_STRING = ""; CONTROL_OFF = NO; CONTROL_OFF_INT = 0; CONTROL_OFF_DOUBLE = 0.000000; CONTROL_OFF_STRING = ""; SLIDER_RANGE_MAX = 10; SLIDER_VALUE_MIN = 0.000000; SLIDER_VALUE_STEP = 0.100000; } PANEL_ITEM { ITEM_NAME = "パワー収穫率"; ITEM_TYPE = SLIDER; VAR_NAME = WORLD.HARVEST; CONTROL_ON = NO; CONTROL_ON_INT = 0; CONTROL_ON_DOUBLE = 1.000000; CONTROL_ON_STRING = ""; CONTROL_OFF = NO; CONTROL_OFF_INT = 0; CONTROL_OFF_DOUBLE = 0.000000; CONTROL_OFF_STRING = ""; SLIDER_RANGE_MAX = 100; SLIDER_VALUE_MIN = 0.000000; SLIDER_VALUE_STEP = 0.010000; } PANEL_ITEM { ITEM_NAME = "偶然性:標準偏差"; ITEM_TYPE = EDIT_BOX; VAR_NAME = WORLD.CONTINGENCY_STDV; CONTROL_ON = NO; CONTROL_ON_INT = 0; CONTROL_ON_DOUBLE = 1.000000; CONTROL_ON_STRING = ""; CONTROL_OFF = NO; CONTROL_OFF_INT = 0; CONTROL_OFF_DOUBLE = 0.000000; CONTROL_OFF_STRING = ""; SLIDER_RANGE_MAX = 1; SLIDER_VALUE_MIN = 0.000000; SLIDER_VALUE_STEP = 1.000000; } PANEL_ITEM { ITEM_NAME = "バランサー"; ITEM_TYPE = TOGGLE; VAR_NAME = WORLD.BALANCERFLG; CONTROL_ON = NO; CONTROL_ON_INT = 1; CONTROL_ON_DOUBLE = 0.000000; CONTROL_ON_STRING = ""; CONTROL_OFF = NO; CONTROL_OFF_INT = 0; CONTROL_OFF_DOUBLE = 0.000000; CONTROL_OFF_STRING = ""; SLIDER_RANGE_MAX = 1; SLIDER_VALUE_MIN = 0.000000; SLIDER_VALUE_STEP = 1.000000; } } //------------------ 説明用HTMLテキスト --------------- //------------------ 空間初期値データ設定部 --------------- SPACE_INITIAL { } //------------------ レポート出力情報設定部 --------------- REPORT_INFO { REPORT_NAME = ""; FIELD_DELIMITER = " "; } //------------------ その他のデータ設定部 --------------- OTHERS_DATA { INDENT = 1; FONT_NAME = "MS ゴシック"; FONT_WIDTH = 0; FONT_HEIGHT = -13; FONT_WEIGHT = 200; FONT_ITALIC = 0; FONT_CHARSET = 128; WINDOW_HIDE_RUN = 0; POSITION_X = 76; POSITION_Y = -11; SIZE_X = 357; SIZE_Y = 922; } //------------------ 再生用ログデータ ---------------