//====================================================================/
//                                                                    /
// KK-Multi Agent Simulator for Java                                  /
//                                                                    /
//====================================================================/

Version = 1.0;



//-------------------------------------------------------
// Component Tree
//-------------------------------------------------------
UNIVERSE {
    Space 空間(10,10),Square_2D(50, 68, !Loop, North, 1){
        AgtType 人(10, 10)[0] {
            Dim X(10, 10) As Double = (0.0);
            Dim Y(100, 10) As Double = (0.0);
            Dim Direction(190, 10) As Double = (0.0);
            Dim Layer(0, 0) As Integer = (0);
        }
        AgtType 人2(10, 10)[0] {
            Dim X(10, 10) As Double = (0.0);
            Dim Y(100, 10) As Double = (0.0);
            Dim Direction(190, 10) As Double = (0.0);
            Dim Layer(0, 0) As Integer = (0);
        }
        Dim 高さ(0, 0)[50][68][1] As Integer = ();
    }
    Dim 人2の数(10, 10) As Integer = (0);
}


//-------------------------------------------------------
// Agent Variable Initial Data
//-------------------------------------------------------
Initial_Value {
    UNIVERSE.人2の数 = 1(5);
    UNIVERSE.空間.高さ = 1(3400*0);
}


//-------------------------------------------------------
// Agent Rule
//-------------------------------------------------------
#begin_rule UNIVERSE
Univ_Init{

	Dim 人の集合 As AgtSet
	Dim 人の集合2 As AgtSet
	Dim i As Integer


	// 人の生成
	CreateAgt(Universe.空間.人)

	// 人2の生成
	For i=1 To Universe.人2の数
		CreateAgt(Universe.空間.人2)
	Next i

	MakeAgtSet(人の集合, Universe.空間.人)
	MakeAgtSet(人の集合2, Universe.空間.人2)
	MergeAgtSet(人の集合, 人の集合2)

	RandomPutAgtSetCell(人の集合, False)

}

Univ_Step_Begin{

}

Univ_Step_End{

}

Univ_Finish{

}

#end_rule UNIVERSE




//-------------------------------------------------------
// Agent Rule
//-------------------------------------------------------
#begin_rule UNIVERSE.空間.人
Agt_Init{

	// 方向を決める
	My.Direction = 360 * Rnd()
}


Agt_Step{

	Dim 歩幅 As Double


	// 方向を変える
	Turn(180 * Rnd() - 90)

	// 前へ進む
	歩幅 = 255/(Universe.空間.高さ(My.X, My.Y)+1)
	歩幅 = 歩幅 / 2
	Forward(歩幅)
}

#end_rule UNIVERSE.空間.人




//-------------------------------------------------------
// Agent Rule
//-------------------------------------------------------
#begin_rule UNIVERSE.空間.人2
Agt_Init{
	// 方向を決める
	My.Direction = 360 * Rnd()
	
}

Agt_Step{
	
	Dim 歩幅 As Double
	Dim col As AgtSet
	Dim n As Integer
	
	// 方向を変える
	Turn(180 * Rnd() - 90)

	// 一歩前へ
	歩幅 = 255/(Universe.空間.高さ(My.X, My.Y)+1)
	歩幅 = 歩幅 / 2
	Forward(歩幅)
	
	MakeOneAgtSetAroundOwn(col, 1, Universe.空間.人, False)
	n = CountAgtSet(col)
	
	If n > 0 Then
		終了処理()
	End If
}

Sub 終了処理()
{
	// ファイル出力
	OpenFileCSV("count.txt", 1, 3)		// ファイル1を追記モードでオープン
	WriteFileCSV(1, "最終カウント数 = ", false)		// 書き出し
	WriteFileCSV(1, GetCountStep(), true)	// 書き出し(改行付き)
	CloseFileCSV(1)			// クローズ

	// 終了メッセージ表示
	ExitSimulationMsg("逮捕!")

}
#end_rule UNIVERSE.空間.人2




//-------------------------------------------------------
// Simulation Definition Division
//-------------------------------------------------------
Single_Simulation {
    Step_Max = 0;
    Time_Max = 0;
    End_Condition = "";
    Exec_Wait = 0;
    Exec_Order = Random;
    Exec_Order_Random_First_Step_Only = No;
    Random_Seed = 0;
    Log_File = "", Fixed, Append, 0;
    Replay_Log_File = "", Fixed, Append, 0;
    Redraw_Timing = Step;
    Redraw_Interval = 0;
    Garbage_Interval = 10;
}


//-------------------------------------------------------
// Simulation Loop Definition Division
//-------------------------------------------------------
Repeat_Simulation {
    Value_Change = None;
    Repeat_Max = 1;
}


//-------------------------------------------------------
// 2 Dimension Map Display Definition Division
//-------------------------------------------------------
Map_Output {
    Map_Space_Name = "Universe.空間";
    Map_Name = "マップ";
    Font_Name = "Dialog";
    Font_Char_Set = 0;
    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, 49, 67;
    Ruled_Line = No;
    Remarks = Yes;
    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 = "yama.gif";
    Disable = No;
    Position_x = 257;
    Position_y = 2;
    Size_x = 534;
    Size_y = 447;
    Origin_Position = 1;
    Output {
        Map_Element_Name = "逃亡";
        Map_Element = Agent_Variable;
        Output_Expression = "UNIVERSE.空間.人";
        Draw_Line = No;
        Collection_Name = "";
        Line_Type = 0;
        Line_Arrow = 0;
        Line_Width = 0;
        Line_Color = 0, 0, 0;
        Agent_Color = 0,0,255;
        Marker_Id = 4;
        Icon_Type = 0;
        Icon_Var_Name = "";
        Icon_Transparent = No;
        Icon_Enlarg_Reduce = No;
        Icon_File_Name = "";
        Num_Display = No;
        Num_Var_Name = "";
    }
    Output {
        Map_Element_Name = "追跡";
        Map_Element = Agent_Variable;
        Output_Expression = "UNIVERSE.空間.人2";
        Draw_Line = No;
        Collection_Name = "";
        Line_Type = 0;
        Line_Arrow = 0;
        Line_Width = 0;
        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 = No;
        Num_Var_Name = "";
    }
}


//-------------------------------------------------------
// Control Panel Definition Division
//-------------------------------------------------------
Control_Panel {
    Display_Area = 768, 121, 163, 108;
    Panel_Item {
        Item_Type = Slider;
        Item_Name = "追跡者の数";
        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.人2の数;
        Slider_Range_Max = 9;
        Slider_Value_Min = 1.0;
        Slider_Value_Step = 1.0;
        Slider_Value = "4";
    }
}


//-------------------------------------------------------
// Space Initial Value Definition Divsion
//-------------------------------------------------------
Space_Initial {
    Space_Item {
        Compo_Path_Name = "Universe.空間.高さ";
        Marker_Id = 1;
        Compo_Kind = Compo_Var;
        Space_Color_Min = 255, 255, 255;
        Space_Color_Max = 0, 0, 255;
        Space_Draw_Range = 0.0, 255.0;
        Space_Display = 0;
    }
}


//-------------------------------------------------------
// 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 = 255, 255, 255;
    Window_Hide_Run = 1;
    Debug_Position_x = 75;
    Debug_Position_y = 75;
    Debug_Size_x = 400;
    Debug_Size_y = 200;
    Console_Position_x = 2;
    Console_Position_y = 389;
    Console_Size_x = 600;
    Console_Size_y = 205;
}