Html/Javascript widget

Monday 14 July 2014

Common Data Structures in C#

As used in Unity 3d, that is! Today we are going to review some basic data structures and the right syntax within which they are arranged in C#.

Queue

A queue in computer programming stands for a sort of array of the first in first out kind. This is comprised of a rank of items being entered into a set and then the first item inserted is also the first one to be taken out. The items assigned to the queue can be strings (ASCII characters that don`t take part in any kind of specific calculation), integers, float (a special kind of integer that supports an impressive amount of decimal digits) etc. The basic syntax is as follows:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class QueueManager : MonoBehaviour
//this is important. When dealing with C sharp within a common Unity Engine domain,
//it is necessary to declare a class (a class basically carries your main program)as public
//inheriting MonoBehaviour. It is crucial to the successful compilation of your program for it to //inherit MonoBehaviour because that`s what will interpret your code as more fitting in an
// in-game environment than that of a common application. Therefore, you shall make your mission
// to have your public class inherit MonoBehaviour. Also note that the public class name
// will always be named after the script created in the game object screen
{

public Queue <string> panhandle = new  Queue <string> ();
/* Pay heed to the way the above statement looks like. We start off by declaring a variable of the queue kind. Except that you don`t declare it the usual way. Before moving on, notice that the queue is to accessed publicly anywhere in your project. That`s why it was made necessary to state that it is of the public kind. AFter making it clear that you`re declaring a public queue variable, you need to specify what kind of data will be inserted into this queue. This is specified between < >. In the example above, it will take in string variables.

Ok, so far you know that every queue that for the life of you you have to declare should follow the following pattern:
1- access level (public, private etc)
2- the key word `Queue`
3- what kind of variables will come into this (<string>, <int>, <float> etc)

This should be enough for you to witness the mighty power of a newly declared queue, right?
Again, do recall that life is full to the brimming with glaring exception that are only there to mar the beautiful thought process that you have allowed to shape up in your bonse. After making sure that your queue is of the public kind and that it will be receiving strings, you should prepare it for future use. That`s right, you should set this to be started in the program. This is accomplished with `new`. You have basically created  a queue data structure and now the compiler needs to understand that it is a new queue. Worse yet, it needs to be told that it is a new Queue that will store strings. Hence the  <string> bit.

The last tidbit are the round brackets enclosing themselves. () are a common staple of object oriented programming and apparently necessary for the public declaration of a queue to be complete.

From what you can glean by reading the above it is possible to conclude that:
1- a queue should first be determined whether it will be of the public kind
2- it is always necessary to specify the type of variables that are going to be administered to the declared public queue
3- don`t forget to give your queue a name. Here it is going to be called `panhandle`.
4- It will receive (hence the equal symbol) a new queue. You can think of the process as a soulless body lying prostate on the ground. Provided that it remains soulless, it will be of no use. As soon as it welcomes a warm and amiable soul, the body will be ready to serve whomever its master is.
5- it will receive a new attribute, which calls for the specification that it is a queue for <string>
6- () is a common staple of queues, stacks and lists.

public Queue <string> panhandle = new Queue <string> ()

After this thorough understanding behind the rationale for creating a queue, you can type this up without giving it much thought!

void Start()
{
// here is everything that is going to take place at the game`s start
panhandle.Enqueue("Damnd");
//there you have it. You`ve included your first item in the queue. A string named "Damnd".
//notice the imperative command `enqueue` to make this happen
panhandle.Enqueue("Abigail");
panhandle. Enqueue("Eddi E.");
panhandle.Enqueue("Won Won");

//we`ve added a total of 4 <string> items to our queue.
 //it might be interesting to create a loop to check the <string> variables in the queue.

foreach  (string number in panhandle)
{
Debug.Log (number);
//number was a quick string created only to be a reference to access the queue
}

//one might want to display their neat queue. Debug.Log is the best option for a quick Print.Out //command

Debug.Log

//If we need to take an item out of the queue, we simply use Dequeue ().No need to specify which //item will be withdrawn becauseit will always be the first one in.
}

void Update ()
{
}

}}
.....................

Let`s create a complete application to highlight the use of queues:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class queuemanager : MonoBehaviour {

public Queue <string> elements = new Queue <string> ();

void Start ()
elements.Enqueue ("Kung Lao");
elements.Enqueue ("Tony Marquez");
elements.Enqueue ("Goro");

foreach (string number in elements)
{
Debug.Log (number);
}

void Update ()
{
if (Input.GetKeyUp (KeyCode.Space))
{
elements.Dequeue ();
Debug.Log ("___");

foreach (string number in elements)
{
Debug.Log (number);
}}}

.............................

List

A list is, at its most basic concept, a queue, bar the except that it doesn`t necessarily follow the first in last in pattern.

Example:

using EngineUnity;
using System.Collections;
using System.Collections.Generic;

public class listmanager : MonoBehaviour {

public list <int> listofintegers = new list <int> ();

void Start ()
{
listofintegers.Add (1);
listofintegers.Add (2) ;
listofintegers.Add(3);
listofintegers.Removeat (0);
listofintegers.Remove(2);

//(0) simply means that we are going to remove the item at the top of the list.
//Remove(2) will remove 2 items at once off the list

for (int i=0; i<listofintegers.Count;i++)
{
Debug.Log (listofintegers[i]):
}
}
void Update ()
{
}
}

................................

Stack

Another kind of queue, except that it is of the first in last out kind.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class stackmanager : MonoBehaviour
{

public stack <string> staxrcool = new stack <string> ();

void Start ()
{

staxrcool.Push ("Akuma");
staxrcool.Push ("Gouki");
staxrcool.Push ("Shin Gouki");

// you may be intelligent enough to have noticed that to add items to stack is to push them in.

staxrcool.Pop ();
//Pop removes one item from the stack. Again, the last one in is always the first to leave.

}

void Update ()
{
}

}


Sunday 6 July 2014

Tennis players are individuals, not one-man countries

I acknowledge the reality of people having to "come from" somewhere, but I tend to see the players (in slams at least) as individuals rather than representatives of a certain country, so to me the under-representation of a nation in the 3rd round of the men's is just, well, one of those things. More shocking to me was the early exit of the likes of Rafa, Roger etc in the previous tournament of what turned out to be one of those peculiar Wimbledons that happens from time to time.

Friday 4 July 2014

French toast

French Toast. Image courtesy of wikipedia.org
French toast (often known as Eggy Bread in parts of the United Kingdom, pain perdu in French) is a popular breakfast food in North America, Europe, Bermuda and Brazil. French toast is made with bread and eggs, with milk commonly added. According to what is popular in local cuisine, many of the spices that are added to bread or egg dishes are included in cooking. This versatile dish is often topped with sugar, butter, fruit, syrup, or other items.

 Preparation

Slices of bread are dipped in a beaten egg mixture. The slices of egg-coated bread are then placed on a frying pan or griddle prepared with a coat of butter or oil, and cooked until both sides are browned and the egg has cooked through.

According to wikipedia.org, the cooked slices can be served with a variety of toppings, including jam, butter, peanut butter, honey, Marmite, vegemite, maple syrup, fruit syrup, molasses, apple sauce, beans, beef, lard, whipped cream, fruit, tomato sauce (when powdered sugar/sugar is not used), chocolate, sugar, yogurt, powdered sugar, marmalade, bacon, duck fat (in Northern Ireland), treacle, cheese (often with ham), gravy or various nuts such as pecans. Heating the oil/butter with chopped garlic, chillies or onions is an effective way to add extra flavour to the dish.
A bunch of slices of French Toast.


Variations

Stuffed French toast is two pieces of French toast that are stuffed with bananas, strawberries, or other fruit. It is usually topped with butter, maple syrup, and powdered sugar.

In the United Kingdom it is often savory and known as either "eggy bread" or "Gypsy toast" or just "bread dipped in egg" in South East Wales. It is also sometimes known by the rather grand title of "Poor Knights of Windsor". Another name occasionally used is "French fried bread" but this should not be confused with "fried bread", which is white bread fried in butter or fat left over from frying bacon or sausages. One variation has marmite spread on the bread before dipping.

In Italy a variation is served known as mozzarella in carrozza (literally "mozzarella in carriage"). In this version a slice of fresh mozzarella is sandwiched between two slices of bread and the whole dipped in egg and fried. It can be seasoned with salt, but is not sweet like French toast nor is it eaten for breakfast. It is often topped with tomato sauce, which is then sometimes garnished with some chopped parsley and grated cheese to make 3 broad stripes of green, white and red, curiosuly enough, the colours of the Italian flag.

In Portugal, it is called fatias douradas or rabanadas and is typically made during Christmas, out of slices of bread leftovers (when it's too hard to be consumed the normal way) soaked in milk to soften it, dipped in beaten egg, deep-fried in olive oil and then dipped in sugar and cinnamon or a syrup made with water, sugar, cinnamon sticks and lemon skin. It is usually eaten cold for dessert.

In Spain, it is called torrijas and is typically made during Lent, out of thick slices of bread soaked in milk or wine, dipped in egg, fried and then drenched in spiced honey.

In New York and in Jewish-American communities, it is a common to make it with Challah. The richness of the sweet egg bread complements the richness of the French toast preparation. In many Jewish-American households it is traditional to use the leftover challah from Friday night Sabbath dinner to make French toast on Sunday morning. The slightly stale challah absorbs the egg or milk-and-egg mixture more readily and cooks into a custard-like central hub for the slices of French toast.

In the Western and Southwestern United States, it is common for some restaurants will prepare it with Sourdough bread.

In Australia and New Zealand, French toast is a breakfast or brunch dish, made by pan-frying individual sliced bread or baguette slices dipped in the egg mixture identical to American preparations. It is sometimes served with banana and fried bacon, and topped with maple syrup. Another popular variation in New Zealand uses a mixture of eggs yolks, milk and grated cheese to make a savory breakfast food.

In Germany, the Arme Ritter (literally poor knights) are made from bread leftovers as fast and simple meal. There are several local alternatives in serving: with a mix of sugar and cinnamon, filled with plum-jam or with vanilla sauce. Sometimes it is made with wine instead of milk, and therefore called Betrunkene Jungfrau, drunken virgin.

In India, the version is salted rather than sweet. The egg is beaten with milk, salt, green chili and chopped onion. Bread is dunked into this mixture and is deep fried in butter or cooking oil. In India locals enjoy seasoning the slices with ketchup.

History and geographic spread

French toast originated as a way to use day-old or stale bread (some breads, French bread especially, become stale after one day). Whereas a stale, crunchy bread might seem unappetizing, soaking the bread in eggs and frying it solved that problem. The precise origins of the recipe are unknown, although a version appears in the 4th century CE Roman cookbook, often attributed to Apicius ("Aliter dulcia: siligineos rasos frangis, et buccellas maiores facies. in lacte infundis, frigis [et] in oleo, mel superfundis et inferes." - "Another sweet: Break grated Sigilines (a kind of wheat bread), and make larger bites. Soak in milk, fry in oil, douse in honey and serve."). This was also known as Pan Dulcis.

French Toast for brunch.

Pain Perdu with syrup, fruit and creme anglaise.
Hong Kong style French Toast typically served in Chan Chan Tengs. Toppings include syrup and a slab of butter.