Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

KoduConditionScored.cc

Go to the documentation of this file.
00001 // Tekkodu Library
00002 #include "Kodu/KoduWorld.h"
00003 #include "Kodu/General/GeneralMacros.h"
00004 #include "Kodu/Primitives/KoduConditionScored.h"
00005 
00006 namespace Kodu {
00007 
00008     bool KoduConditionScored::evaluate(const KoduWorld& kWorldState) {
00009         // boolean return value
00010         bool rv = false;
00011         // get the latest score
00012         int score = KoduWorld::getScoreValue(designator);
00013         if (numericsWereSpecified) {
00014             // get a (constant/random) value from the numeric generator
00015             int value = numericGen.getNumericValue();
00016             // check the inequality type
00017             // equals
00018             if (type == CT_EQUALS && score == value) {
00019                 rv = true;
00020             }
00021             // not equals
00022             else if (type == CT_NOT_EQUALS && score != value) {
00023                 rv = true;
00024             }
00025             // greater than or equal to
00026             else if (type == CT_GT_EQUAL && score >= value) {
00027                 rv = true;
00028             }
00029             // lesser than or equal to
00030             else if (type == CT_LT_EQUAL && score <= value) {
00031                 rv = true;
00032             }
00033             // above
00034             else if (type == CT_ABOVE && score > value) {
00035                 rv = true;
00036             }
00037             // below
00038             else if (type == CT_BELOW && score < value) {
00039                 rv = true;
00040             }
00041         }
00042         // numerics were not specified
00043         else {
00044             if (score != lastRecordedValue) {
00045                 lastRecordedValue = score;
00046                 rv = true;
00047             }
00048         }
00049         // check if the "not" modifier is enabled
00050         if (notModifierEnabled)
00051             rv = !rv;
00052         return rv;
00053     }
00054     
00055     bool KoduConditionScored::isSameTypeAs(const KoduPrimitive* kPrimitive) {
00056         return (dynamic_cast<const KoduConditionScored*>(kPrimitive) != NULL);
00057     }
00058 
00059     void KoduConditionScored::reinitialize() {
00060         KoduCondition::reinitialize();
00061     }
00062 
00063     void KoduConditionScored::printAttrs() const {
00064         KoduCondition::printAttrs();
00065         PRINT_ATTRS("Not enabled", notModifierEnabled);
00066         PRINT_ATTRS("Numerics were specified", numericsWereSpecified);
00067         std::cout << "Inequality: ";
00068         switch (type) {
00069             case CT_EQUALS:
00070                 std::cout << "equals";
00071                 break;
00072 
00073             case CT_NOT_EQUALS:
00074                 std::cout << "not equals";
00075                 break;
00076 
00077             case CT_GT_EQUAL:
00078                 std::cout << "greater than or equal to (>=)";
00079                 break;
00080             
00081             case CT_LT_EQUAL:
00082                 std::cout << "lesser than or equal to (<=)";
00083                 break;
00084 
00085             case CT_ABOVE:
00086                 std::cout << "above";
00087                 break;
00088 
00089             case CT_BELOW:
00090                 std::cout << "below";
00091                 break;
00092             case INVALID:
00093               std::cout << "**invliad**";
00094         }
00095         std::cout << std::endl;
00096         numericGen.printAttrs();
00097         std::cout << "Scored designator: " << designator << std::endl;
00098     }
00099 } // end of Kodu namespace

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:43 2016 by Doxygen 1.6.3