Skip to content

Instantly share code, notes, and snippets.

@djanatyn
Created November 14, 2022 01:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djanatyn/b593219710c38e6f8a82d790d4197392 to your computer and use it in GitHub Desktop.
Save djanatyn/b593219710c38e6f8a82d790d4197392 to your computer and use it in GitHub Desktop.
chocobo coloring prolog

So in Final Fantasy 14, you have a cute companion, a Chocobo! You can change the color of your Chocobo:

The default color of the chocobo is Desert Yellow. Players can change the color of their Chocobo by feeding them snacks...

The color value is tracked in RGB, so the default value (Desert Yellow) is 216/180/87.

Different fruit will change the Chocobo color in different ways:

Snack                  Effect                                                 R      G      B
---------------------  -----------------------------------------------------  -----  -----  -----
Xelphatol Apple        Increases red hue, also reduces blue and green hues.   +5     -5     -5 
Mamook Pear            Increases green hue, also reduces blue and red hues.   -5     +5     -5 
O'Ghomoro Berries      Increases blue hue, also reduces green and red hues.   -5     -5     +5 
Doman Plum             Reduces red hue, also increases blue and green hues.   -5     +5     +5 
Valfruit               Reduces green hue, also increases blue and red hues.   +5     -5     +5 
Cieldalaes Pineapple   Reduces blue hue, also increases green and red hues.   +5     +5     -5 
Han Lemon              Restores to default Desert Yellow color                              

However, you have to take care to avoid going under 0 or over 255 in any hue, or the fruit won't work!

The player has to be careful not to exceed 255 or go below 0 in any of the three RGB values, or the change will fail.

So, my goal is to figure out:

What fruit do I need to feed my Chocobo to get from Hunter Green (40/75/38) to Ink Blue (26/31/39)?

And even better:

What order should the fruit be fed in to avoid going over max?

I think that I can use SWI Prolog's CLPFD library for this! I was thinking I should create relations representing the number of fruits, something like:

zozo = [40,75,38].
goal = [26, 31, 39].

apple(zozo, goal, NumberApples).

An apple will change:

  • Red + 5
  • Green - 5
  • Blue - 5

And then I imagine I have to describe how NumberApples is related to the solution, something like...

apple([StartRed, StartGreen, StartBlue], [GoalRed, GoalGreen, GoalBlue], NumApples) :-
  GoalRed #= StartRed + (NumApples * 5),
  GoalGreen #= StartGreen + (NumApples * -5),
  GoalBlue #= StartBlue + (NumApples * -5).

And I think we need to have all the fruits represented here...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment