diff --git a/SA_DiceComparators.h b/SA_DiceComparators.h new file mode 100644 index 0000000..8e8e0e9 --- /dev/null +++ b/SA_DiceComparators.h @@ -0,0 +1,17 @@ +// +// SA_DiceComparators.h +// DieBot Mobile +// +// Created by Sandy Achmiz on 5/4/16. +// +// + +#import + +#ifndef SA_DiceComparators_h +#define SA_DiceComparators_h + +NSComparisonResult compareEvaluatedExpressionsByResult(NSDictionary* expression1, NSDictionary *expression2); +NSComparisonResult compareEvaluatedExpressionsByAttemptBonus(NSDictionary* expression1, NSDictionary *expression2); + +#endif /* SA_DiceComparators_h */ \ No newline at end of file diff --git a/SA_DiceComparators.m b/SA_DiceComparators.m new file mode 100644 index 0000000..1e617fb --- /dev/null +++ b/SA_DiceComparators.m @@ -0,0 +1,43 @@ +// +// SA_DiceComparators.m +// DieBot Mobile +// +// Created by Sandy Achmiz on 5/4/16. +// +// + +#import "SA_DiceComparators.h" + +#import "SA_DiceExpressionStringConstants.h" + +NSComparisonResult compareEvaluatedExpressionsByResult(NSDictionary* expression1, NSDictionary *expression2) +{ + if([expression1[SA_DB_RESULT] integerValue] < [expression2[SA_DB_RESULT] integerValue]) + { + return NSOrderedAscending; + } + else if([expression1[SA_DB_RESULT] integerValue] > [expression2[SA_DB_RESULT] integerValue]) + { + return NSOrderedDescending; + } + else + { + return NSOrderedSame; + } +} + +NSComparisonResult compareEvaluatedExpressionsByAttemptBonus(NSDictionary* expression1, NSDictionary *expression2) +{ + if([expression1[SA_DB_OPERAND_RIGHT][SA_DB_RESULT] integerValue] < [expression2[SA_DB_OPERAND_RIGHT][SA_DB_RESULT] integerValue]) + { + return NSOrderedAscending; + } + else if([expression1[SA_DB_OPERAND_RIGHT][SA_DB_RESULT] integerValue] > [expression2[SA_DB_OPERAND_RIGHT][SA_DB_RESULT] integerValue]) + { + return NSOrderedDescending; + } + else + { + return NSOrderedSame; + } +}