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

Version = 1.0;



//-------------------------------------------------------
// Component Tree
//-------------------------------------------------------
UNIVERSE {
    Space TUKUE(0,0),Square_2D(51, 51, !Loop, North, 1){
        AgtType Mikan(0, 0)[0] {
            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 fuhai(0, 0) As Boolean = (0);
            Dim iro(0, 0) As Integer = (0);
        }
        Dim Houshi(0, 0) <1> [51][51][1] As Integer = (2601*0);
    }
    Dim MikanSousuu(0, 0) As Integer = (0);
    Dim RRate(0, 0) As Double = (0.0);
}


//-------------------------------------------------------
// Agent Variable Initial Data
//-------------------------------------------------------
Initial_Value {
    UNIVERSE.MIKANSOUSUU = 1(735);
    UNIVERSE.RRATE = 1(0.01);
}


//-------------------------------------------------------
// Agent Rule
//-------------------------------------------------------
#begin_rule UNIVERSE
Univ_Init{
dim i as integer

for i = 0 to universe.MikanSousuu - 1
	createagt(universe.TUKUE.Mikan)
next i
}

Univ_Step_Begin{

}

Univ_Step_End{

}

Univ_Finish{

}
#end_rule UNIVERSE




//-------------------------------------------------------
// Agent Rule
//-------------------------------------------------------
#begin_rule UNIVERSE.TUKUE.MIKAN
Agt_Init{

	Movetocenter()
	Movetospaceowncell(20)
	my.iro = RGB(255, 170, 0)
	if rnd() < universe.RRate then 
		my.fuhai = true
		my.iro = RGB(150, 70, 0)		
	end if

}

Agt_Step{
dim i as integer
dim j as integer

if my.fuhai == true  then
	for i = 0 to 2
		for j = 0 to 2
		universe.TUKUE.Houshi(my.X+i-1, my.Y+j-1, 0) = universe.TUKUE.Houshi(my.X+i-1, my.Y+j-1, 0) + 1
		next j
	next i
	for i = 0 to 4
		for j = 0 to 4
		universe.TUKUE.Houshi(my.X+i-2, my.Y+j-2, 0) = universe.TUKUE.Houshi(my.X+i-2, my.Y+j-2, 0) + 1
		next j
	next i
else
	if gethistory(universe.TUKUE.Houshi(my.X, my.Y, 0), 1)>= 5  then
		my.fuhai = true
		my.iro = RGB(150, 70, 0)
	end if
end if 
}
#end_rule UNIVERSE.TUKUE.MIKAN




//-------------------------------------------------------
// 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 = 1;
    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.TUKUE";
    Map_Name = "tukue";
    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, 50, 50;
    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 = "";
    Disable = No;
    Position_x = 382;
    Position_y = 49;
    Size_x = 535;
    Size_y = 546;
    Origin_Position = 2;
    Output {
        Map_Element_Name = "Mikan";
        Map_Element = Agent_Variable;
        Output_Expression = "Universe.TUKUE.Mikan";
        Draw_Line = No;
        Collection_Name = "";
        Line_Type = 0;
        Line_Arrow = 0;
        Line_Width = 0;
        Line_Color = 0, 0, 0;
        Agent_Color = "Universe.TUKUE.Mikan.iro";
        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 = "";
    }
    Output {
        Map_Element_Name = "housi";
        Map_Element = Space_Variable;
        Output_Expression = "UNIVERSE.TUKUE.Houshi";
        Space_Draw_Range = 0.0, 5.0;
        Space_Color_Min = 255, 255, 255;
        Space_Color_Max = 0, 102, 0;
        Marker_Id = 0;
        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 = 772, 91, 191, 206;
    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.MikanSousuu;
        Slider_Range_Max = 1000;
        Slider_Value_Min = 0.0;
        Slider_Value_Step = 1.0;
        Slider_Value = "735";
    }
    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.RRate;
        Slider_Range_Max = 50;
        Slider_Value_Min = 0.0;
        Slider_Value_Step = 0.01;
        Slider_Value = "1";
    }
}


//-------------------------------------------------------
// 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 = 75;
    Debug_Position_y = 75;
    Debug_Size_x = 400;
    Debug_Size_y = 200;
    Console_Position_x = -18;
    Console_Position_y = 332;
    Console_Size_x = 300;
    Console_Size_y = 250;
}