3 Comments

image

Scrabble is funny, and to play it with friends even more. Especially because you can spread the game throughout your day. But I am a coder, I like math more than words. So to keep up with this Wordfeud trend, I need help. So why not code a helper?

I only use the Dutch library which is a modified version of opentaal. I downloaded the ‘opentaal’ library from this url:

http://www.opentaal.org/bestanden/doc_download/18-woordenlijst-v-210g-bronbestanden-

and used the following 48 lines of C# code to make a small helper.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;

namespace Opentaal
{
    public partial class Form1 : Form
    {
        private static List<string> _lijst;

        public Form1()
        {
            _lijst = File.ReadLines("OpenTaal.txt").ToList();
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length > 0)
            {
                string zt = textBox1.Text.Trim(); // search parameter
                switch (comboBox1.SelectedItem.ToString())
                {
                    case "Begint met":
                        ShowFound(_lijst.Where(p => p.StartsWith(zt)).ToList());
                        break;
                    case "Eindigt op":
                        ShowFound(_lijst.Where(p => p.EndsWith(zt)).ToList());
                        break;
                    case "Bevat":
                        ShowFound(_lijst.Where(p => p.Contains(zt)).ToList());
                        break;
                }
            }
        }

        private void ShowFound(List<string> l)
        {
            textBox2.Clear(); // for second search
            foreach (string st in l.OrderBy(s => s)) // order by alfabet 
                textBox2.Text += st + Environment.NewLine;
            int eind = textBox2.Text.LastIndexOf(Environment.NewLine);
            textBox2.Text = textBox2.Text.Substring(0, eind); // remove last linebreak
        }
    }
}

 

You can take this code and make more search options. Please note that the opentaal library is released under a creative commons license.

kick it on DotNetKicks.com Shout it

Post on LinkedIn