//====================================================================/ // / // KK-Multi Agent Simulator for Java / // / //====================================================================/ Version = 1.0; //------------------------------------------------------- // Component Tree //------------------------------------------------------- UNIVERSE { Space Space_P(0,0),Square_2D(100, 100, Loop, North, 1){ AgtType Prisoner(0, 0)[8] { Dim X(0, 0) As Double = (0.0); Dim Y(0, 0) As Double = (0.0); Dim Layer(0, 0) As Integer = (0); Dim Direction(0, 0) As Double = (0.0); Dim Score(0, 0) <2> As Integer = (0); Dim Hand(0, 0) <10> As Integer = (); Dim Opponents_ID(0, 0) As Integer = (0); Dim Opponents(0, 0) As AgtSet = (); Dim Stratedy(0, 0) As String = (""); Dim Number(0, 0) As Integer = (0); Dim Frag(0, 0) As Integer = (0); } } Dim Stp(0, 0) As Integer = (0); Dim Prisoners(0, 0) As AgtSet = (); Dim N_Prisoners(0, 0) As Integer = (0); Dim Stratedy00(0, 0) As String = (""); Dim Stratedy01(0, 0) As String = (""); Dim Stratedy02(0, 0) As String = (""); Dim Stratedy03(0, 0) As String = (""); Dim Stratedy04(0, 0) As String = (""); Dim Stratedy05(0, 0) As String = (""); Dim Stratedy06(0, 0) As String = (""); Dim Stratedy07(0, 0) As String = (""); } //------------------------------------------------------- // Agent Variable Initial Data //------------------------------------------------------- Initial_Value { UNIVERSE.STRATEDY00 = 1("TFTT"); UNIVERSE.STRATEDY01 = 1("TFT"); UNIVERSE.STRATEDY02 = 1("Friedman"); UNIVERSE.STRATEDY03 = 1("Davis"); UNIVERSE.STRATEDY04 = 1("Joss"); UNIVERSE.STRATEDY05 = 1("rTFT"); UNIVERSE.STRATEDY06 = 1("Random"); UNIVERSE.STRATEDY07 = 1("Tullock"); } //------------------------------------------------------- // Agent Rule //------------------------------------------------------- #begin_rule UNIVERSE Univ_Init{ dim Prisoners As Agtset dim i As integer //囚人を配置します MakeAgtSet(Prisoners, Universe.Space_P.Prisoner) For i = 0 to CountAgtSet(Prisoners)-1 Universe.Space_P.Prisoner.X(i) = 50 + 30*cos(DegreeToRad((360/ CountAgtSet(Prisoners))*i)) Universe.Space_P.Prisoner.Y(i) = 50 + 30*sin(DegreeToRad((360/ CountAgtSet(Prisoners))*i)) Next i } Univ_Step_Begin{ //ステップは自分で数えます Universe.Stp = Universe.Stp + 1 // 囚人の組み合わせを決める。100ステップごとに組み替えをする。 Dim SelectedPrisonerA As Agt Dim SelectedPrisonerB As Agt Dim a As Integer Dim b As Integer if Universe.Stp mod 100 == 1 then MakeAgtSet(Universe.Prisoners, Universe.Space_P.Prisoner) START: Universe.N_Prisoners = CountAgtSet(Universe.Prisoners) //囚人集合が空になっていたら止める If Universe.N_Prisoners <= 1 then Goto PASS end if //囚人集合から二人選ぶ a = Int(rnd() * Universe.N_Prisoners) BACK: b = Int(rnd()* Universe.N_Prisoners) If a == b then Goto BACK end if //二人を選ぶ SelectedPrisonerA = GetAgt(Universe.Prisoners, a) SelectedPrisonerB = GetAgt(Universe.Prisoners, b) //相手を認識させる SelectedPrisonerA.Opponents_ID = SelectedPrisonerB.Number SelectedPrisonerB.Opponents_ID = SelectedPrisonerA.Number //囚人集合から選ばれた二人を除く RemoveAgt(Universe.Prisoners, SelectedPrisonerA) RemoveAgt(Universe.Prisoners, SelectedPrisonerB) Goto START end if PASS: } Univ_Step_End{ If Universe.Stp == 5000 then ExitSimulationMsg("Fin") end if } Univ_Finish{ } #end_rule UNIVERSE //------------------------------------------------------- // Agent Rule //------------------------------------------------------- #begin_rule UNIVERSE.SPACE_P.PRISONER Agt_Init{ my.Number = my.id // 戦略を決める if my.id == 0 then my.Stratedy = Universe.Stratedy00 elseif my.id == 1 then my.Stratedy = Universe.Stratedy01 elseif my.id == 2 then my.Stratedy = Universe.Stratedy02 elseif my.id == 3 then my.Stratedy = Universe.Stratedy03 elseif my.id == 4 then my.Stratedy = Universe.Stratedy04 elseif my.id == 5 then my.Stratedy = Universe.Stratedy05 elseif my.id == 6 then my.Stratedy = Universe.Stratedy06 elseif my.id == 7 then my.Stratedy = Universe.Stratedy07 end if } Agt_Step{ // 対戦相手を把握しておく ClearAgtset(My.Opponents) AddAgt(My.Opponents, Universe.Space_P.Prisoner(my.Opponents_ID)) // 手を考える(奇数ステップ) If Universe.Stp mod 2 == 1 then //でたらめ戦略 If StrComp(my.Stratedy , "Random") == 0 then if rnd() < 0.5 then my.Hand = 1 else my.Hand = 2 end if end if //悪人 If StrComp(my.Stratedy , "allD") == 0 then my.Hand = 2 end if //善人 If StrComp(my.Stratedy , "allC") == 0 then my.Hand = 1 end if //しっぺ返し戦略 If StrComp(my.Stratedy , "TFT") == 0 then if Universe.Stp mod 100 == 1 then my.Hand = 1 else If StrComp(GetHistory(Universe.Space_P.Prisoner.Hand(My.Opponents_ID),1), 2 ) == 0 then my.Hand = 2 else my.Hand = 1 end if end if end if //堪忍袋戦略 If StrComp(my.Stratedy , "TFTT") == 0 then if Universe.Stp mod 100 == 1 then my.Hand = 1 my.Frag = 0 end if if Universe.Stp mod 100 >= 2 then If GetHistory(Universe.Space_P.Prisoner.Hand(My.Opponents_ID),1) == 2 and my.Frag >= 2 then my.Hand = 2 else my.Hand = 1 end if end if end if //逆しっぺ返し戦略 If StrComp(my.Stratedy , "rTFT") == 0 then if Universe.Stp mod 100 == 1 then my.Hand = 2 else If StrComp(GetHistory(Universe.Space_P.Prisoner.Hand(My.Opponents_ID),1), 2 ) == 0 then my.Hand = 2 else my.Hand = 1 end if end if end if //フリードマン戦略 If StrComp(my.Stratedy , "Friedman") == 0 then if Universe.Stp mod 100 == 1 then my.Hand = 1 my.Frag = 1 else If my.Frag == 1 then my.Hand =1 else my.Hand = 2 end if if StrComp(Universe.Space_P.Prisoner.Hand(My.Opponents_ID), 2 ) == 0 then my.Frag = 2 end if end if end if //デーヴィス戦略 If StrComp(my.Stratedy , "Davis") == 0 then if Universe.Stp mod 100 == 1 then my.Frag = 1 end if if Universe.Stp mod 100 <= 10 then my.Hand = 1 if Universe.Space_P.Prisoner.Hand(My.Opponents_ID) == 2 then my.Frag = 2 end if end if if Universe.Stp mod 100 > 10 then If my.Frag == 1 then my.Hand =1 else my.Hand = 2 end if end if end if //ヨッス戦略 If StrComp(my.Stratedy , "Joss") == 0 then if Universe.Stp mod 100 == 1 then my.Hand = 1 else If StrComp(GetHistory(Universe.Space_P.Prisoner.Hand(My.Opponents_ID),1), 2 ) == 0 then my.Hand = 2 else if rnd()<0.9 then my.Hand = 1 else my.Hand = 2 end if end if end if end if //テュロック戦略 If StrComp(my.Stratedy , "Tullock") == 0 then if Universe.Stp mod 100 == 1 then my.Frag = 0 end if if Universe.Stp mod 100 > 10 then if rnd()*100< (my.Frag * 20-10) then my.Hand = 1 else my.Hand = 2 end if end if end if end if // スコアを計算する(偶数ステップ) If Universe.Stp mod 2 == 0 then If StrComp(my.Hand, 1) == 0 and StrComp(Universe.Space_P.Prisoner.Hand(my.Opponents_ID), 1) == 0 then my.Score = my.Score + 1 elseIf StrComp(my.Hand, 1) == 0 and StrComp(Universe.Space_P.Prisoner.Hand(my.Opponents_ID), 2) == 0 then my.Score = my.Score - 1 elseIf StrComp(my.Hand, 2) == 0 and StrComp(Universe.Space_P.Prisoner.Hand(my.Opponents_ID), 1) == 0 then my.Score = my.Score + 2 elseIf StrComp(my.Hand, 2) == 0 and StrComp(Universe.Space_P.Prisoner.Hand(my.Opponents_ID), 2) == 0 then my.Score = my.Score + 0 end if //テュロック戦略(相手を評価する) If StrComp(my.Stratedy , "Tullock") == 0 then if Universe.Stp mod 100 <= 10 then my.Hand = 1 if Universe.Space_P.Prisoner.Hand(My.Opponents_ID) == 1 then my.Frag = my.Frag + 1 end if end if end if //堪忍袋戦略(相手を評価する) If StrComp(my.Stratedy , "TFTT") == 0 then if Universe.Space_P.Prisoner.Hand(My.Opponents_ID) == 2 then my.Frag = my.Frag + 1 elseif Universe.Space_P.Prisoner.Hand(My.Opponents_ID) == 1 then my.Frag = 0 end if end if //確認用出力 // if my.id == 0 then // Println(My.Stratedy) // Println(My.Hand) // Println(Universe.Space_P.Prisoner.Hand(my.Opponents_ID)) // Println(My.Score-GetHistory(My.Score, 1)) // end if end if } #end_rule UNIVERSE.SPACE_P.PRISONER //------------------------------------------------------- // Simulation Definition Division //------------------------------------------------------- Single_Simulation { Step_Max = 0; Time_Max = 0; End_Condition = ""; Exec_Wait = 0; Exec_Order = Random; Random_Seed = 0; Log_File = "", Fixed, Append, 0; Replay_Log_File = "", Fixed, Append, 0; Redraw_Timing = Step; Redraw_Interval = 1; Garbage_Interval = 10; } //------------------------------------------------------- // Simulation Loop Definition Division //------------------------------------------------------- Repeat_Simulation { Value_Change = None; Repeat_Max = 1; } //------------------------------------------------------- // Bar Graph Output Definition Division //------------------------------------------------------- Bar_Graph { Graph_Name = "Scores"; Font_Name = "Dialog"; Font_Char_Set = 81; Font_Size = 12.0; Font_Style = 0; Font_Color = 0, 0, 0; Font_Background_Color = 255, 255, 255; Title = "Scores"; Axis_Label = "", ""; Scale = 0, 0.0, 0, 200.0, 0, 500.0; Remarks = No; Legend_Pos = Top; Background_Color = 0, 0, 0; Disable = No; Position_x = 336; Position_y = 327; Size_x = 500; Size_y = 300; Piled_Bar_Graph = No; Bar_Direction = 2; Output { Graph_Element_Name = "00"; Line_Color = 255, 204, 51; Line_Width = 10; Marker_Id = 0; Output_Expression = "Universe.Space_P.Prisoner.Score(0)"; Expression_Value_Display = Yes; Effective_Fraction_Figures = 0; } Output { Graph_Element_Name = "01"; Line_Color = 255, 204, 0; Line_Width = 10; Marker_Id = 0; Output_Expression = "Universe.Space_P.Prisoner.Score(1)"; Expression_Value_Display = Yes; Effective_Fraction_Figures = 0; } Output { Graph_Element_Name = "02"; Line_Color = 255, 204, 51; Line_Width = 10; Marker_Id = 0; Output_Expression = "Universe.Space_P.Prisoner.Score(2)"; Expression_Value_Display = Yes; Effective_Fraction_Figures = 0; } Output { Graph_Element_Name = "03"; Line_Color = 255, 204, 51; Line_Width = 10; Marker_Id = 0; Output_Expression = "Universe.Space_P.Prisoner.Score(3)"; Expression_Value_Display = Yes; Effective_Fraction_Figures = 0; } Output { Graph_Element_Name = "04"; Line_Color = 255, 204, 0; Line_Width = 10; Marker_Id = 0; Output_Expression = "Universe.Space_P.Prisoner.Score(4)"; Expression_Value_Display = Yes; Effective_Fraction_Figures = 0; } Output { Graph_Element_Name = "05"; Line_Color = 255, 204, 0; Line_Width = 10; Marker_Id = 0; Output_Expression = "Universe.Space_P.Prisoner.Score(5)"; Expression_Value_Display = Yes; Effective_Fraction_Figures = 0; } Output { Graph_Element_Name = "06"; Line_Color = 255, 204, 0; Line_Width = 10; Marker_Id = 0; Output_Expression = "Universe.Space_P.Prisoner.Score(6)"; Expression_Value_Display = Yes; Effective_Fraction_Figures = 0; } Output { Graph_Element_Name = "07"; Line_Color = 255, 204, 0; Line_Width = 10; Marker_Id = 0; Output_Expression = "Universe.Space_P.Prisoner.Score(7)"; Expression_Value_Display = Yes; Effective_Fraction_Figures = 0; } } //------------------------------------------------------- // 2 Dimension Map Display Definition Division //------------------------------------------------------- Map_Output { Map_Space_Name = "UNIVERSE.SPACE_P"; Map_Name = "Space_P"; Font_Name = "Dialog"; Font_Char_Set = 81; Font_Size = 12.0; Font_Style = 0; Font_Color = 0, 0, 0; Font_Background_Color = 255, 255, 255; Title = ""; Axis_Label = "", ""; Draw_Range = 0, 0, 100, 100; Ruled_Line = No; Remarks = No; Legend_Pos = Top; Background_Color = 0, 0, 0; Background_Transparent = No; Target_Layer = 0; Coordinate_Display = No; Space_Kind = Square_2D; BG_Pict = No; BG_Type = 0; BG_Var_Name = ""; BG_File_Name = ""; Disable = No; Position_x = 242; Position_y = 5; Size_x = 500; Size_y = 300; Origin_Position = 2; Output { Map_Element_Name = "Prisoner"; Map_Element = Agent_Variable; Output_Expression = "UNIVERSE.SPACE_P.PRISONER"; Draw_Line = Yes; Collection_Name = "UNIVERSE.SPACE_P.PRISONER.OPPONENTS"; Line_Type = 1; Line_Arrow = 3; Line_Width = 1; Line_Color = 0, 0, 0; Agent_Color = 255,0,0; Marker_Id = 1; Icon_Type = 0; Icon_Var_Name = ""; Icon_Transparent = No; Icon_Enlarg_Reduce = No; Icon_File_Name = ""; Num_Display = Yes; Num_Var_Name = "UNIVERSE.SPACE_P.PRISONER.NUMBER"; } } //------------------------------------------------------- // Control Panel Definition Division //------------------------------------------------------- Control_Panel { Display_Area = 822, 210, 175, 473; Panel_Item { Item_Type = Edit_Box; Item_Name = "Stratedy00"; Display_Area = 0, 0, 0, 0; Font_Name = ""; Font_Char_Set = 0; Font_Size = 0.0; Font_Style = 0; Font_Color = 0, 0, 0; Font_Background_Color = 0, 0, 0; Var_Name = UNIVERSE.STRATEDY00; Text_Data = "TFTT"; } Panel_Item { Item_Type = Edit_Box; Item_Name = "Stratedy01"; Display_Area = 0, 0, 0, 0; Font_Name = ""; Font_Char_Set = 0; Font_Size = 0.0; Font_Style = 0; Font_Color = 0, 0, 0; Font_Background_Color = 0, 0, 0; Var_Name = UNIVERSE.STRATEDY01; Text_Data = "TFT"; } Panel_Item { Item_Type = Edit_Box; Item_Name = "Stratedy02"; Display_Area = 0, 0, 0, 0; Font_Name = ""; Font_Char_Set = 0; Font_Size = 0.0; Font_Style = 0; Font_Color = 0, 0, 0; Font_Background_Color = 0, 0, 0; Var_Name = UNIVERSE.STRATEDY02; Text_Data = "Friedman"; } Panel_Item { Item_Type = Edit_Box; Item_Name = "Stratedy03"; Display_Area = 0, 0, 0, 0; Font_Name = ""; Font_Char_Set = 0; Font_Size = 0.0; Font_Style = 0; Font_Color = 0, 0, 0; Font_Background_Color = 0, 0, 0; Var_Name = UNIVERSE.STRATEDY03; Text_Data = "Davis"; } Panel_Item { Item_Type = Edit_Box; Item_Name = "Stratedy04"; Display_Area = 0, 0, 0, 0; Font_Name = ""; Font_Char_Set = 0; Font_Size = 0.0; Font_Style = 0; Font_Color = 0, 0, 0; Font_Background_Color = 0, 0, 0; Var_Name = UNIVERSE.STRATEDY04; Text_Data = "Joss"; } Panel_Item { Item_Type = Edit_Box; Item_Name = "Stratedy05"; Display_Area = 0, 0, 0, 0; Font_Name = ""; Font_Char_Set = 0; Font_Size = 0.0; Font_Style = 0; Font_Color = 0, 0, 0; Font_Background_Color = 0, 0, 0; Var_Name = UNIVERSE.STRATEDY05; Text_Data = "rTFT"; } Panel_Item { Item_Type = Edit_Box; Item_Name = "Stratedy06"; Display_Area = 0, 0, 0, 0; Font_Name = ""; Font_Char_Set = 0; Font_Size = 0.0; Font_Style = 0; Font_Color = 0, 0, 0; Font_Background_Color = 0, 0, 0; Var_Name = UNIVERSE.STRATEDY06; Text_Data = "Random"; } Panel_Item { Item_Type = Edit_Box; Item_Name = "Stratedy07"; Display_Area = 0, 0, 0, 0; Font_Name = ""; Font_Char_Set = 0; Font_Size = 0.0; Font_Style = 0; Font_Color = 0, 0, 0; Font_Background_Color = 0, 0, 0; Var_Name = UNIVERSE.STRATEDY07; Text_Data = "Tullock"; } } //------------------------------------------------------- // Space Initial Value Definition Divsion //------------------------------------------------------- Space_Initial { } //------------------------------------------------------- // Other Miscellaneous Data Definition Division //------------------------------------------------------- Others_Data { Indent = 4; Rule_Colored = Yes; Font_Name = "Dialog"; Font_Char_Set = 0; Font_Size = 12.0; Font_Style = 0; Font_Color = 0, 0, 0; Font_Background_Color = 0, 0, 0; Window_Hide_Run = 1; Debug_Position_x = 155; Debug_Position_y = 299; Debug_Size_x = 400; Debug_Size_y = 200; Console_Position_x = 119; Console_Position_y = 244; Console_Size_x = 413; Console_Size_y = 260; }