public override bool isValid(AIState currentState) { if (!currentState.CurrentPlayerState.HandsFree()) { return(false); } if (currentState.ItemStateList[id].MyItemType != ItemType.BOARD) { return(false); } else { BoardState board = currentState.ItemStateList[id] as BoardState; if (currentState.ItemStateList[board.HoldingItemID].MyItemType != ItemType.INGREDIENT) { return(false); } else { IngredientState ingredient = currentState.ItemStateList[board.HoldingItemID] as IngredientState; return(!ingredient.IsPrepared); } } }
public override AIState ApplyAction(AIState currentState) { AIState cloneState = base.ApplyAction(currentState); foreach (int id in cloneState.IngredientStateIndexList) { IngredientState ingredient = cloneState.ItemStateList[id] as IngredientState; if (ingredient.ingredientType == spawnType && !ingredient.IsSpawned) { ingredient.IsSpawned = true; if (spawnType == IngredientType.MUSHROOM) { cloneState.mushroomSpawnCount++; } if (spawnType == IngredientType.ONION) { cloneState.onionSpawnCount++; } cloneState.CurrentPlayerState.PickUp(ingredient.ID); break; } } return(cloneState); }
public float GetHeuristic(AIState state) { int h = 0; float epsilon = 2.0f; foreach (int ingredientID in state.IngredientStateIndexList) { IngredientState ingredient = (state.ItemStateList[ingredientID] as IngredientState); if (ingredient.ingredientType == IngredientType.ONION) { if (!ingredient.IsSpawned) { h += 1; } if (!ingredient.IsPrepared) { h += 1; } if (!ingredient.IsInMeal) { h += 1; } } } //Debug.Log("Implement a heuristic here"); return(h * epsilon); }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (this == obj) { return(true); } IngredientState otherState = obj as IngredientState; if (otherState == null) { return(false); } return(this.ID == otherState.ID && this.ingredientType == otherState.ingredientType && this.IsSpawned == otherState.IsSpawned && this.IsPrepared == otherState.IsPrepared && this.IsInMeal == otherState.IsInMeal); }
public Ingredient.IIngredientState CreateIngredientState() { var ingredient = new IngredientState(); ingredient.Guid = Guid.NewGuid(); _context.IngredientStates.Add(ingredient); return(ingredient); }
public override void LoadState(ItemState state) { IngredientState iState = state as IngredientState; MyIngredientType = iState.ingredientType; IsSpawned = iState.IsSpawned; IsPrepared = iState.IsPrepared; IsInMeal = iState.IsInMeal; UpdateVisual(); }
public Ingredient(string name, float spicy, float chunky, bool isMeat) { prefab = null; currentState = IngredientState.WHOLE; this.ingredientName = name; spicyness = spicy; chunkyness = chunky; this.isMeat = isMeat; //colour = null; }
public override AIState ApplyAction(AIState currentState) { AIState cloneState = base.ApplyAction(currentState); BoardState board = cloneState.ItemStateList[id] as BoardState; IngredientState ingredient = cloneState.ItemStateList[board.HoldingItemID] as IngredientState; //Debug.Log("To get this up and running quickly, preparing an ingredient is a simple boolean flip"); ingredient.IsPrepared = true; return(cloneState); }
public bool IsGoal(AIState currentState) { foreach (int ingredientID in currentState.IngredientStateIndexList) { IngredientState ingredient = currentState.ItemStateList[ingredientID] as IngredientState; if (ingredient.ingredientType == IngredientType.ONION) { if (ingredient.IsPrepared == false) { return(false); } } } return(true); }
public void Copy(Ingredient thingToCopy) { this.ingredientName = thingToCopy.ingredientName; this.spicyness = thingToCopy.spicyness; this.chunkyness = thingToCopy.chunkyness; this.isMeat = thingToCopy.isMeat; this.currentState = thingToCopy.currentState; this.prefab = thingToCopy.prefab; this.halfedPrefab = thingToCopy.halfedPrefab; this.quateredPrefab = thingToCopy.quateredPrefab; this.blendedPrefab = thingToCopy.blendedPrefab; this.colour = thingToCopy.colour; this.colourTag = thingToCopy.colourTag; this.sweetness = thingToCopy.sweetness; this.icon = thingToCopy.icon; }
public int[,] GetMealIngredientCounts() { if (MealIngredientCounts != null) { return(MealIngredientCounts); } MealIngredientCounts = new int[MealStateIndexList.Count, NUM_INGREDIENT_TYPES]; for (int i = 0; i < MealStateIndexList.Count; ++i) { MealState meal = ItemStateList[MealStateIndexList[i]] as MealState; foreach (int ingID in meal.ContainedIngredientIDs) { IngredientState ingredient = ItemStateList[ingID] as IngredientState; ++MealIngredientCounts[i, (int)ingredient.ingredientType]; } } return(MealIngredientCounts); }
private int IngredientHeuristic(IngredientState iState) { if (!iState.IsSpawned) { return(3); } if (!iState.IsPrepared) { return(2); } if (!iState.IsInMeal) { return(1); } return(0); }
public void Init(AIState state) { // This preallocates an array to hold all of the heuristic numbers. int NUM_INGREDIENT_TYPES = Enum.GetNames(typeof(IngredientType)).Length; HeuristicPerIngredient = new List <List <int> >(NUM_INGREDIENT_TYPES); for (int ingredientType = 0; ingredientType < NUM_INGREDIENT_TYPES; ++ingredientType) { int count = 0; foreach (int ingID in state.IngredientStateIndexList) { IngredientState iState = state.ItemStateList[ingID] as IngredientState; if (ingredientType == (int)iState.ingredientType) { ++count; } } HeuristicPerIngredient.Add(new List <int>(count)); } }
/// <summary> /// Used to get all of the valid actions for the current state /// </summary> /// <returns></returns> public List <Action> GetValidActions(AIState state) { List <Action> validActions = new List <Action>(); //Waiting around validActions.Add(new IdleAction()); //Things you can do when your hands are free if (state.CurrentPlayerState.HandsFree()) { //Spawning items foreach (IngredientType type in System.Enum.GetValues(typeof(IngredientType))) { SpawnAction spawnAction = new SpawnAction(type); if (spawnAction.isValid(state)) { validActions.Add(spawnAction); } } PickUpAction pickupAction; //Picking up everything //Ingredients foreach (int ingredientID in state.IngredientStateIndexList) { IngredientState ingredient = state.ItemStateList[ingredientID] as IngredientState; if (ingredient.IsSpawned && !ingredient.IsInMeal) { pickupAction = new PickUpAction(ingredient.ID); validActions.Add(pickupAction); } } //Pots foreach (int potID in state.PotStateIndexList) { PotState pot = state.ItemStateList[potID] as PotState; pickupAction = new PickUpAction(pot.ID); validActions.Add(pickupAction); } //Plates foreach (int plateID in state.PlateStateIndexList) { PlateState plate = state.ItemStateList[plateID] as PlateState; pickupAction = new PickUpAction(plate.ID); validActions.Add(pickupAction); } PrepareAction prepAction; foreach (int boardID in state.BoardStateIndexList) { BoardState bState = state.ItemStateList[boardID] as BoardState; if (!bState.IsFree()) { IngredientState iState = state.ItemStateList[bState.HoldingItemID] as IngredientState; if (iState != null && !iState.IsPrepared) { prepAction = new PrepareAction(boardID); validActions.Add(prepAction); } } } } //Things you can do when you have something in hand else { DropOffAction dropoffAction; TransferAction transferAction; ItemState itemState = state.ItemStateList[state.CurrentPlayerState.HoldingItemID]; ItemType type = itemState.MyItemType; if (type == ItemType.INGREDIENT) { //Putting things on the table foreach (int tableID in state.TableStateIndexList) { TableSpace table = state.ItemStateList[tableID] as TableSpace; if (table.IsFree()) { dropoffAction = new DropOffAction(table.ID); validActions.Add(dropoffAction); } } //Moving ingredients to a cutting board foreach (int boardID in state.BoardStateIndexList) { BoardState board = state.ItemStateList[boardID] as BoardState; if (board.IsFree()) { dropoffAction = new DropOffAction(board.ID); validActions.Add(dropoffAction); } } if ((itemState as IngredientState).IsPrepared) { //Moving ingredients to a pot foreach (int potID in state.PotStateIndexList) { PotState pot = state.ItemStateList[potID] as PotState; MealState meal = state.ItemStateList[pot.mealID] as MealState; if (meal.MealSize() + 1 <= PotState.MAX_ITEMS_PER_POT && !meal.IsBurnt()) { dropoffAction = new DropOffAction(pot.ID); validActions.Add(dropoffAction); } } //Moving ingredients to a plate foreach (int plateID in state.PlateStateIndexList) { PlateState plate = state.ItemStateList[plateID] as PlateState; MealState meal = state.ItemStateList[plate.mealID] as MealState; if (!plate.IsSubmitted && !meal.IsBurnt()) { dropoffAction = new DropOffAction(plate.ID); validActions.Add(dropoffAction); } } } } if (type == ItemType.POT) { PotState pot = itemState as PotState; MealState meal = state.ItemStateList[pot.mealID] as MealState; //Putting the pot on the table foreach (int tableID in state.TableStateIndexList) { TableSpace table = state.ItemStateList[tableID] as TableSpace; if (table.IsFree()) { dropoffAction = new DropOffAction(table.ID); validActions.Add(dropoffAction); } } //Moving meal to a pot transferAction = new TransferAction(Item.NOTHING_ID); foreach (int potID in state.PotStateIndexList) { transferAction.id = potID; if (transferAction.isValid(state)) { validActions.Add(transferAction); transferAction = new TransferAction(Item.NOTHING_ID); } } //Moving the meal to another plate foreach (int plateID in state.PlateStateIndexList) { transferAction.id = plateID; if (transferAction.isValid(state)) { validActions.Add(transferAction); transferAction = new TransferAction(Item.NOTHING_ID); } } } if (type == ItemType.PLATE) { PlateState plate = itemState as PlateState; //Putting things on the table foreach (int tableID in state.TableStateIndexList) { TableSpace table = state.ItemStateList[tableID] as TableSpace; if (table.IsFree()) { dropoffAction = new DropOffAction(table.ID); validActions.Add(dropoffAction); } } //If the plate is non-empty MealState heldMeal = state.ItemStateList[plate.mealID] as MealState; if (heldMeal.IsSpawned()) { //Submitting the meal if (heldMeal.IsCooked()) { SubmitOrderAction submitAction = new SubmitOrderAction(); validActions.Add(submitAction); } //Moving meal to a pot transferAction = new TransferAction(Item.NOTHING_ID); foreach (int potID in state.PotStateIndexList) { transferAction.id = potID; if (transferAction.isValid(state)) { validActions.Add(transferAction); transferAction = new TransferAction(Item.NOTHING_ID); } } //Moving the meal to another plate foreach (int plateID in state.PlateStateIndexList) { transferAction.id = plateID; if (transferAction.isValid(state)) { validActions.Add(transferAction); transferAction = new TransferAction(Item.NOTHING_ID); } } } } } return(validActions); }
public float GetHeuristic(AIState state) { if (state.Heuristic >= 0) { return(state.Heuristic); } if (HeuristicPerIngredient == null) { Init(state); } else { for (int i = 0; i < HeuristicPerIngredient.Count; ++i) { HeuristicPerIngredient[i].Clear(); } } foreach (int ingredientID in state.IngredientStateIndexList) { IngredientState iState = state.ItemStateList[ingredientID] as IngredientState; HeuristicPerIngredient[(int)iState.ingredientType].Add(IngredientHeuristic(iState)); } int ingredientHeuristicSum = 0; for (int i = 0; i < HeuristicPerIngredient.Count; ++i) { HeuristicPerIngredient[i].Sort(); ingredientHeuristicSum += HeuristicPerIngredient[i].Take(CountOfEachIngredient[i]).Sum(); } int cooktimeHeuristic = 0; int submittedHeuristic = 0; int[,] mealIngredientCounts = state.GetMealIngredientCounts(); for (int goalIndex = 0; goalIndex < Goal.GoalRecipes.Count; ++goalIndex) { int neededCookTime = Goal.GoalRecipes[goalIndex].Count * MealState.COOK_TIME_PER_INGREDIENT + 1; int minGoalCookTime = neededCookTime; bool submitted = false; List <int> goalRecipe = Goal.IngredientCountsPerRecipe[goalIndex]; for (int mealListIndex = 0; mealListIndex < state.MealStateIndexList.Count; ++mealListIndex) { MealState meal = state.ItemStateList[state.MealStateIndexList[mealListIndex]] as MealState; if (!meal.IsSpawned()) { continue; } int onionCount = mealIngredientCounts[mealListIndex, (int)IngredientType.ONION]; int mushroomCount = mealIngredientCounts[mealListIndex, (int)IngredientType.MUSHROOM]; if (meal.IsBurnt() || onionCount > goalRecipe[(int)IngredientType.ONION] || mushroomCount > goalRecipe[(int)IngredientType.MUSHROOM]) { continue; } // Found qualifying meal. bool foundPlate = false; // Is there a plate holding this meal...? foreach (int plateID in state.PlateStateIndexList) { PlateState plate = state.ItemStateList[plateID] as PlateState; if (plate.mealID != meal.ID) { continue; } foundPlate = true; if (plate.IsSubmitted) { // Check if the meal completely matches if (meal.IsCooked() && onionCount == goalRecipe[(int)IngredientType.ONION] && mushroomCount == goalRecipe[(int)IngredientType.MUSHROOM]) { // Good job. submitted = true; minGoalCookTime = 0; } else { // Submitted meal that doesn't match the recipe or is uncooked // skip. } } else { // Qualifying meal on a plate that hasn't been submitted. int currentCookDuration = Mathf.Min(meal.cookDuration, meal.ContainedIngredientIDs.Count * MealState.COOK_TIME_PER_INGREDIENT + 1); int remainingCookTime = Mathf.Max(0, neededCookTime - currentCookDuration); minGoalCookTime = Mathf.Min(minGoalCookTime, remainingCookTime); } break; } if (!foundPlate) { // Meal is in a pot. int currentCookDuration = Mathf.Min(meal.cookDuration, meal.ContainedIngredientIDs.Count * MealState.COOK_TIME_PER_INGREDIENT + 1); int remainingCookTime = Mathf.Max(0, neededCookTime - currentCookDuration); minGoalCookTime = Mathf.Min(minGoalCookTime, remainingCookTime); } } //cooktimeHeuristic = Mathf.Max(cooktimeHeuristic, minGoalCookTime); cooktimeHeuristic += minGoalCookTime; submittedHeuristic += submitted ? 0 : 1; } //state.Heuristic = Mathf.Max(ingredientHeuristicSum + submittedHeuristic, cooktimeHeuristic); //state.Heuristic = ingredientHeuristicSum + submittedHeuristic; float parallelism = Mathf.Min(Goal.GoalRecipes.Count, state.PotStateIndexList.Count); state.Heuristic = ingredientHeuristicSum + (cooktimeHeuristic / parallelism) + submittedHeuristic; return(state.Heuristic); }
public void CookedIngredient() { state = IngredientState.COOKED; }
public static void CreateIngredient(Transform originalIngredient, Transform newIngredient, IngredientState state) { switch (state) { case IngredientState.WHOLE: break; case IngredientState.HALF: // Just because we don't have any art for blended foods, ill make the soup orb a blended ingredient by changing the tag and adding an Ingredient script. // if (!newIngredient.GetComponent <Ingredient>()) { newIngredient.gameObject.AddComponent <Ingredient>(); } newIngredient.gameObject.GetComponent <Ingredient>().Copy(originalIngredient.GetComponent <Ingredient>()); newIngredient.tag = "Ingredient"; newIngredient.GetComponent <Rigidbody>().isKinematic = false; // Editing the cunkyness value. // newIngredient.GetComponent <Ingredient>().chunkyness /= 2; newIngredient.GetComponent <Ingredient>().currentState = IngredientState.HALF; Debug.Log("SLICED HALF"); break; case IngredientState.QUARTER: if (!newIngredient.GetComponent <Ingredient>()) { newIngredient.gameObject.AddComponent <Ingredient>(); } newIngredient.gameObject.GetComponent <Ingredient>().Copy(originalIngredient.GetComponent <Ingredient>()); newIngredient.tag = "Ingredient"; newIngredient.GetComponent <Rigidbody>().isKinematic = false; // Editing the cunkyness value. // newIngredient.GetComponent <Ingredient>().chunkyness /= 4; newIngredient.GetComponent <Ingredient>().currentState = IngredientState.QUARTER; Debug.Log("SLICED QUARTER"); break; } }