How to win at the Roulette?
A simple roulette bet yields 47% maximum winning chance. But if you have more rounds to play, you can achieve better odds. It all depends on your strategy. I designed an algorithm that yields 65% chance of winning some money after few rounds. To tell the whole history I wrote a whole open source C# .NET project that enables developers to write and test its own algorithms, for any kind of game of chance. All you need to is to checkout the project or download the zip and implement IAlgorithm. To see the results you should run the console application. If you agree with the fitness function would you write a better algorithm?
Saturday, September 26, 2009
Tuesday, September 15, 2009
How to customize route icons when using Google Maps API
I just commited an example of how to do that, check the javascript source code at:
Saturday, August 22, 2009
Complete .NET IEquatable implementation reference
I finally wrote a sample code that shows the correct way to implement all IEquatable related methods:
The unit tests that justify each line of code are there:
Thursday, July 2, 2009
Adding recombination to Image Vectorization Genetic Programming
After reading the Roger Alsing's arcticle about his Evo Lisa, a genetic approach to image vectorization, I decided to build my own version of it from scratch using C# .NET and TDD. The result is published at Google Code project hosting licensed under LGPL. The key diferences are:
1. It uses only Triangles instead of polygons or splines.
2. It accepts a population parameter.
3. When the population > 1 then it does recombination (cross-over).
Tuesday, June 30, 2009
How to convert MP3 files to WAV files in .NET (C#)
I have successfully converted compressed audio to PCM files with the Alvas.Audio .NET library. Its FAQ shows how to convert a WAV to a MP3 but not the contrary. So I had to write my own code:
static void Main(string[] args) { string mp3File = @"Theme - Simpsons.mp3"; string wavFile = @"Theme - Simpsons.wav"; using (var wr = new Mp3Reader(File.OpenRead(mp3File))) { IntPtr mp3Format = wr.ReadFormat(); byte[] mp3Data = wr.ReadData(); var wavFormat = AudioCompressionManager.GetWaveFormat(mp3Format); Decode2Pcm(ref mp3Format, ref mp3Data, ref wavFormat); MemoryStream ms = new MemoryStream(); using (var output = File.OpenWrite(wavFile)) using (WaveWriter ww = new WaveWriter(output, AudioCompressionManager.FormatBytes(AudioCompressionManager.GetFormatList(wavFormat)[0].FormatHandle))) { ww.WriteData(mp3Data); } } } private static void Decode2Pcm(ref IntPtr format, ref byte[] data, ref WaveFormat wf) { IntPtr newFormat = AudioCompressionManager.GetCompatibleFormat(format, AudioCompressionManager.PcmFormatTag); byte[] buffer = AudioCompressionManager.Convert(format, newFormat, data, false); wf = AudioCompressionManager.GetWaveFormat(newFormat); format = newFormat; data = buffer; }
Thursday, June 11, 2009
Google AppEngine will reduce free quotas to 14%
Google published on its AppEngine blog the plan to reduce the free use quotas to 6.5 CPU-hours and 1.07 gigabytes of outbound transfer, by June 22nd. It's 14% of the current free CPU time quota and 10% of the current bandwith, and 8,000 of the currently free deployed applications will be charged.
Current free quotas:
46.30 CPU hours
10.00 GBytes Outgoing Bandwith
10.00 GBytes Incoming Bandwith
1.00 GBytes Stored Data
2000 Recipients Emailed
Saturday, June 6, 2009
How to draw on a Windows Form using C# .NET
1. Create a new Windows Forms Application on Visual Studio
2. In the design mode click on the form
3. On the properties window click on events
4. Double click the "Paint" event
and the final step:
5. Put the code below in the file that opens:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Bitmap DrawingArea; // Area to draw on.
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DrawingArea = new Bitmap(
this.ClientRectangle.Width,
this.ClientRectangle.Height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using (var canvas = Graphics.FromImage(DrawingArea))
{
canvas.Clear(Color.Transparent);
canvas.FillPolygon(Brushes.Black, new PointF[] { new PointF(10, 10), new PointF(0, 0), new PointF(0, 10) });
}
this.Invalidate();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(DrawingArea, 0, 0, DrawingArea.Width, DrawingArea.Height);
}
}
}
Subscribe to:
Posts (Atom)