[HPforGrownups] computers, magic and complex logic
Dave Hardenbrook
DaveH47 at mindspring.com
Thu Nov 22 04:57:36 UTC 2001
No: HPFGUIDX 29598
Tuesday, November 20, 2001, 9:47:04 PM, frantyck at yahoo.com wrote:
fyc> Hullo. Has anyone considered the possible parallels between the
fyc> design of complex spells and enchantments and computer programming?
There definitely must be programming-like logic for magical things!
Look at the Goblet of Fire... A lot of logic is involved in screening
the champions -- First it has to check that the candidate is from a
legitimate school, then the candidate has to be of age, etc. And the
"code" is modified by master "programmer" Barty Crouch, Jr. If the
incantations for the Goblet was translated to Java, it might look
something like this...
class Goblet_of_Fire
{
private final int numschools = 3;
private String schools[numschools] = "Hogwarts", "Beauxbatons", "Durmstrang";
private CandList Candidates_for_school[numschools] // List of candidates for Hogwarts, Beaubatons, Durmstrang
public void AcceptName() // Function called when a name is entered in the Goblet
{
Student candidate = Read_Name_in_Goblet();
if(candidate->Age() < 17) GrowBeard(); // Champion must be at least 17 years old
else
{
for(int i = 0; i < numschools; i++)
{
if(candidate->School() == schools[i])
Candidates_for_school[i]->Push(); // Store candidate for this school --
// Candidate ignored if school doesn't exist
}
}
}
public void GetChampions() // Function called when Goblet spews out the champions' names
{
// Get a school's champion from the List of the three school's candidates
// (Algorithm for choosing champion in CandList::GetChampion() may be very complex)
//
Student candidate;
for(int i = 0; i < numschools; i++)
{
candidate = Candidates_for_school[school]->GetChampion();
Eject_name_from_Goblet(candidate);
}
}
}
Now here's how it looks after Crouch "reprogrammed" the Goblet
(All he had to do really is add the fourth school to the
school list, and override the age check for Harry):
class Rigged_Goblet_of_Fire
{
// Altered school data
//
private final int numschools = 4;
//
private String schools[numschools] = "Hogwarts", "Beauxbatons", "Durmstrang", "USC";
private CandList Candidates_for_school[numschools] // List of candidates for Hogwarts, Beaubatons, Durmstrang, "USC"
public void AcceptName() // Function called when a name is entered in the Goblet
{
Student candidate = Read_Name_in_Goblet();
// Harry will be the only candidate for "USC" -- Override age check for Harry
//
if(candidate->Name() == "Harry Potter") Candidates_for_school[USC]->Push(candidate);
else
{
if(candidate->Age() < 17) GrowBeard();
else
{
for(int i = 0; i < numschools; i++)
{
if(candidate->School() == schools[i])
Candidates_for_school[i]->Push(candidate); // Store candidate for this school --
} // Candidate ignored if school doesn't exist
}
}
}
public void GetChampions() // Function called when Goblet gets the champions' names
{
// Get a school's champion from the List of the FOUR school's candidates
// (Crouch actually doesn't have to alter this function -- The fourth
// champion will automatically be Harry, the bogus school's only contender)
//
Student candidate;
for(int i = 0; i < numschools; i++)
{
candidate = Candidates_for_school[school]->GetChampion();
Eject_name_from_Goblet(candidate);
}
}
}
So I'd say, yes, logic is needed at least to do powerful magic.
--
Dave
More information about the HPforGrownups
archive