Board index
Programs with AI or Rules Enforcement
Magic: The Gathering - Duels of the Planeswalkers
Programming Talk



An approximation of "add one mana of any color"
Moderator: CCGHQ Admins
1 post
• Page 1 of 1
An approximation of "add one mana of any color"
by thefiremind » 12 Aug 2012, 19:16
I don't want to delude you: I didn't find the ultimate trick, it's just an approximation that works good for very specific purposes. I'm showing you because maybe someone could get inspiration for something better.
I was browsing through the Magic expansions looking at the theme decks, and suddenly I wanted to make a deck inspired from the Sunburst theme deck. Yes, it's crazy, knowing the limitations that we have on mana abilities. But if you think about it, sunburst just requires to spend as many colors of mana as possible, it doesn't matter which ones. So in most cases we want to access the mana that we can't already access. That could be achieved with an "if" chain of GrantAbility: if you can't afford white, then grant the ability for white mana, else if you can't afford blue, then grant the ability for blue mana, else etc...
Looks good, but not good enough. I wanted to give the "if" chain a slight adaptability, so that it tries to grant the most useful mana colors first.
This is what I came up with (ColourToString is a function I had already made some time ago):
I don't even have to give you a list of the possible cases where this method doesn't grant the mana you really need, it's obvious that you can't always rely on this automation. But for the purpose of a sunburst deck, some copies of Birds of Paradise and/or Darksteel Ingot with this code will be useful.
EDIT: A possible variation:
I was browsing through the Magic expansions looking at the theme decks, and suddenly I wanted to make a deck inspired from the Sunburst theme deck. Yes, it's crazy, knowing the limitations that we have on mana abilities. But if you think about it, sunburst just requires to spend as many colors of mana as possible, it doesn't matter which ones. So in most cases we want to access the mana that we can't already access. That could be achieved with an "if" chain of GrantAbility: if you can't afford white, then grant the ability for white mana, else if you can't afford blue, then grant the ability for blue mana, else etc...
Looks good, but not good enough. I wanted to give the "if" chain a slight adaptability, so that it tries to grant the most useful mana colors first.
This is what I came up with (ColourToString is a function I had already made some time ago):
- Code: Select all
ColourToString = function(colour)
-- converts color constants (i.e. COLOUR_RED) to mana strings (i.e. "{R}")
local mana_table = {"{W}", "{U}", "{B}", "{R}", "{G}"}
return mana_table[colour]
end
GetTopColour = function(position, zone, player)
-- makes a top 5 of the most recurrent mana symbols in zone (eventually limited by player), then returns the specified position (as a color constant)
local filter = Object():GetFilter()
local temp_table = {}
local top_table = {}
for i=1,5 do
filter:Clear()
filter:SetZone(zone)
if player ~= nil then
filter:SetPlayer(player)
end
temp_table[i] = filter:ChromaCount(i)
end
for j=1,5 do
local best_position = 1
for i=2,5 do
if temp_table[i] > temp_table[best_position] then
best_position = i
end
end
temp_table[best_position] = -1
top_table[j] = best_position
end
if position > 0 and position < 6 then
return top_table[position]
else
return 0
end
end
GrantManaAbilityByTopColour = function()
-- grants a mana ability according to the top 5 of the most recurrent mana symbols in EffectController's hand
local top_table = {}
local player = EffectController()
for i=1,5 do
top_table[i] = GetTopColour(i, ZONE_HAND, player)
end
if player:CanAfford( ColourToString(top_table[1]) ) == 0 then
Object():GetCurrentCharacteristics():GrantAbility(top_table[1])
elseif player:CanAfford( ColourToString(top_table[2]) ) == 0 then
Object():GetCurrentCharacteristics():GrantAbility(top_table[2])
elseif player:CanAfford( ColourToString(top_table[3]) ) == 0 then
Object():GetCurrentCharacteristics():GrantAbility(top_table[3])
elseif player:CanAfford( ColourToString(top_table[4]) ) == 0 then
Object():GetCurrentCharacteristics():GrantAbility(top_table[4])
elseif player:CanAfford( ColourToString(top_table[5]) ) == 0 then
Object():GetCurrentCharacteristics():GrantAbility(top_table[5])
else
Object():GetCurrentCharacteristics():GrantAbility(top_table[1])
end
end
- Code: Select all
<CONTINUOUS_ACTION>
GrantManaAbilityByTopColour()
</CONTINUOUS_ACTION>
I don't even have to give you a list of the possible cases where this method doesn't grant the mana you really need, it's obvious that you can't always rely on this automation. But for the purpose of a sunburst deck, some copies of Birds of Paradise and/or Darksteel Ingot with this code will be useful.
EDIT: A possible variation:
- Code: Select all
GrantManaAbilityByLeastAvailableColour = function()
-- grants a mana ability according to the least available mana color for EffectController, checking in top 5 order (as the previous function)
local top_table = {}
local availability_table = {}
local player = EffectController()
for i=1,5 do
top_table[i] = GetTopColour(i, ZONE_HAND, player)
end
for i=1,5 do
availability_table[i] = GetTotalManaOfColour(player, top_table[i])
end
local worst_position = 1
for i=2,5 do
if availability_table[i] < availability_table[worst_position] then
worst_position = i
end
end
Object():GetCurrentCharacteristics():GrantAbility(top_table[worst_position])
end
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
Currently busy with life...
-
thefiremind - Programmer
- Posts: 3515
- Joined: 07 Nov 2011, 10:55
- Has thanked: 118 times
- Been thanked: 722 times
1 post
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 4 guests