@@ -813,11 +813,12 @@ public class ScriptExecutor
813
813
private IObjectSelectorProvider objectSelectorProvider ;
814
814
private IGameObjectPropertiesCalculator propCalculator ; // Class which can caclulate interaction positions
815
815
public List < ScriptPair > script ; // Script (filled with subsequent calls of AddAction)
816
+ public List < ScriptLine > sLines ; // Original Script
816
817
private CharacterControl characterControl ; // Class which can execute actions (Walk, Grab, etc.)
817
818
private List < ICameraControl > cameraControls ; // Camera control class
818
819
private int gotoExecDepth ;
819
820
private System . Diagnostics . Stopwatch execStartTime ;
820
- private ProcessingReport report ;
821
+ public ProcessingReport report ;
821
822
private bool randomizeExecution ; // Randomize selection of interaction position
822
823
private Recorder recorder ;
823
824
private int processingTimeLimit = 20 * 1000 ; // Max search time for admissible solution (in milliseconds)
@@ -830,11 +831,11 @@ public class ScriptExecutor
830
831
public static Hashtable actionsPerLine = new Hashtable ( ) ;
831
832
public static int currRunlineNo = 0 ; // The line no being executed now
832
833
public static int currActionsFinished = 0 ; // The number of actions finished for currRunLineNo. Moving to the next line if currActionsFinished == actionsPerLine[currRunlineNo];
834
+
833
835
834
836
// *****
835
837
private TestDriver caller ;
836
838
837
- //private IList<ScriptLine> sLines { get; set; }
838
839
839
840
public ScriptExecutor ( IList < GameObject > nameList , RoomSelector roomSelector ,
840
841
IObjectSelectorProvider objectSelectorProvider , Recorder rcdr , int charIndex , InteractionCache interaction_cache , bool smooth_walk = false )
@@ -851,6 +852,7 @@ public ScriptExecutor(IList<GameObject> nameList, RoomSelector roomSelector,
851
852
852
853
propCalculator = new DefaultGameObjectPropertiesCalculator ( ) ;
853
854
script = new List < ScriptPair > ( ) ;
855
+ sLines = new List < ScriptLine > ( ) ;
854
856
recorder = rcdr ;
855
857
report = new ProcessingReport ( ) ;
856
858
}
@@ -881,11 +883,13 @@ public void Initialize(CharacterControl chc, List<ICameraControl> cac)
881
883
chc . report = report ;
882
884
cameraControls = cac ;
883
885
script . Clear ( ) ;
886
+ sLines . Clear ( ) ;
884
887
}
885
888
886
889
public void ClearScript ( )
887
890
{
888
891
script . Clear ( ) ;
892
+ sLines . Clear ( ) ;
889
893
}
890
894
891
895
private IEnumerable < GameObject > SelectObjects ( IObjectSelector selector )
@@ -3869,7 +3873,7 @@ public ScriptReaderException(string message) :
3869
3873
}
3870
3874
}
3871
3875
3872
- class ScriptLine
3876
+ public class ScriptLine
3873
3877
{
3874
3878
public InteractionType Interaction { get ; set ; }
3875
3879
public IList < Tuple < string , int > > Parameters { get ; set ; }
@@ -3882,19 +3886,71 @@ internal bool CompareParameters(ScriptLine otherSl)
3882
3886
}
3883
3887
}
3884
3888
3885
- public class ScriptReader
3889
+ public class ScriptChecker
3886
3890
{
3887
-
3888
- public static void ReadScript ( ScriptExecutor sExecutor , string fileName ,
3889
- ActionEquivalenceProvider actionEquivProvider , string scriptPath = @"ActionScripts/" )
3891
+ public static List < Tuple < int , Tuple < String , String > > > SolveConflicts ( List < ScriptExecutor > sExecutors )
3890
3892
{
3891
- IList < ScriptLine > sLines = ReadScriptLines ( scriptPath + fileName , actionEquivProvider ) ;
3892
3893
3893
- for ( int i = 0 ; i < sLines . Count ; i ++ )
3894
+ // Solve conflicts when multiple agents are trying to open/grab the same object
3895
+ Dictionary < int , List < int > > dict_conflicts = new Dictionary < int , List < int > > ( ) ;
3896
+ Dictionary < int , InteractionType > action_conflicts = new Dictionary < int , InteractionType > ( ) ;
3897
+ List < Tuple < int , Tuple < String , String > > > conflict_messages = new List < Tuple < int , Tuple < String , String > > > ( ) ;
3898
+ for ( int i = 0 ; i < sExecutors . Count ( ) ; i ++ )
3894
3899
{
3895
- ScriptLineToAction ( sExecutor , i , sLines ) ;
3900
+ for ( int script_index = 0 ; script_index < sExecutors [ i ] . sLines . Count ( ) ; script_index ++ )
3901
+ {
3902
+ if ( sExecutors [ i ] . sLines [ script_index ] . Interaction == InteractionType . OPEN ||
3903
+ sExecutors [ i ] . sLines [ script_index ] . Interaction == InteractionType . CLOSE ||
3904
+ sExecutors [ i ] . sLines [ script_index ] . Interaction == InteractionType . GRAB ) {
3905
+ int index_object = sExecutors [ i ] . sLines [ script_index ] . Parameters [ 0 ] . Item2 ;
3906
+ if ( ! dict_conflicts . ContainsKey ( index_object ) )
3907
+ {
3908
+
3909
+ dict_conflicts [ index_object ] = new List < int > ( ) ;
3910
+ action_conflicts [ index_object ] = sExecutors [ i ] . sLines [ script_index ] . Interaction ;
3911
+ }
3912
+
3913
+ dict_conflicts [ index_object ] . Add ( i ) ;
3914
+ }
3915
+ }
3916
+ }
3917
+
3918
+ foreach ( KeyValuePair < int , List < int > > kvp in dict_conflicts )
3919
+ {
3920
+ if ( kvp . Value . Count ( ) > 1 )
3921
+ {
3922
+ InteractionType conflict_action = action_conflicts [ kvp . Key ] ;
3923
+ int index_char_perform = RandomUtils . Choose ( kvp . Value ) ;
3924
+ for ( int i = 0 ; i < kvp . Value . Count ( ) ; i ++ )
3925
+ {
3926
+ int index_char = kvp . Value [ i ] ;
3927
+ if ( index_char != index_char_perform )
3928
+ {
3929
+ sExecutors [ index_char ] . script . Clear ( ) ;
3930
+ sExecutors [ index_char ] . sLines . Clear ( ) ;
3931
+ Tuple < String , String > ct = new Tuple < String , String > ( "PROCESS UNDEF" , $ "Agent { index_char_perform } tried to do the same action") ;
3932
+ if ( conflict_action == InteractionType . OPEN )
3933
+ ct = new Tuple < String , String > ( "PROCESS OPEN" , $ "Agent { index_char_perform } tried to open the object at the same time") ;
3934
+
3935
+ if ( conflict_action == InteractionType . CLOSE )
3936
+ ct = new Tuple < String , String > ( "PROCESS CLOSE" , $ "Agent { index_char_perform } tried to open the object at the same time") ;
3937
+
3938
+
3939
+ if ( conflict_action == InteractionType . GRAB )
3940
+ ct = new Tuple < String , String > ( "PROCESS GRAB" , $ "Agent { index_char_perform } tried to grab the object at the same time") ;
3941
+
3942
+
3943
+ conflict_messages . Add ( new Tuple < int , Tuple < string , string > > ( index_char , ct ) ) ;
3944
+ }
3945
+ }
3946
+ }
3896
3947
}
3948
+ return conflict_messages ;
3897
3949
}
3950
+ }
3951
+
3952
+ public class ScriptReader
3953
+ {
3898
3954
3899
3955
public static void ParseScript ( List < ScriptExecutor > sExecutors , IList < string > scriptLines ,
3900
3956
ActionEquivalenceProvider actionEquivProvider )
@@ -3918,7 +3974,7 @@ private static void ParseScriptForChar(ScriptExecutor sExecutor, IList<string> s
3918
3974
if ( sl != null )
3919
3975
sLines . Add ( sl ) ;
3920
3976
}
3921
- // sExecutor.sLines = new List<ScriptLine>(sLines);
3977
+ sExecutor . sLines = new List < ScriptLine > ( sLines ) ;
3922
3978
for ( int i = 0 ; i < sLines . Count ; i ++ )
3923
3979
{
3924
3980
ScriptLineToAction ( sExecutor , i , sLines ) ;
@@ -4048,25 +4104,6 @@ private static void ScriptLineToAction(ScriptExecutor sExecutor, int index, ILis
4048
4104
4049
4105
}
4050
4106
4051
- static IList < ScriptLine > ReadScriptLines ( string fileName , ActionEquivalenceProvider actionEquivProvider )
4052
- {
4053
- var result = new List < ScriptLine > ( ) ;
4054
-
4055
- using ( System . IO . StreamReader file = new System . IO . StreamReader ( fileName ) )
4056
- {
4057
- string line ;
4058
- int lineNo = 0 ;
4059
-
4060
- while ( ( line = file . ReadLine ( ) ) != null )
4061
- {
4062
- var sl = ParseLine ( line , lineNo ++ , actionEquivProvider ) ;
4063
-
4064
- if ( sl != null )
4065
- result . Add ( sl ) ;
4066
- }
4067
- }
4068
- return result ;
4069
- }
4070
4107
4071
4108
private static ScriptLine ParseLine ( string line , int lineNo , ActionEquivalenceProvider actionEquivProvider )
4072
4109
{
0 commit comments