Skip to content

Instantly share code, notes, and snippets.

View msadowski's full-sized avatar

Mateusz Sadowski msadowski

View GitHub Profile
private static List<Move> getMoves(List<Point> matches, Point source)
{
List<Move> moves = new List<Move>();
foreach (Point pt in matches)
{
if (pt.X < source.X)
{
moves.Add(new Move(pt, Direction.DOWN));
}
else if (pt.X > source.X)
namespace BejeweledBot
{
public static class ArrExtension
{
public static int TryGetValue(this int[,] arr, int row, int col)
{
bool widthOK = false;
bool heightOK = false;
if (row >= 0 && row < arr.GetLength(0))
widthOK = true;
private static List<Point> getHorizontalMatch(int[,] arr, int row, int col, int distance, int targetValue)
{
int height = arr.GetLength(0);
int width = arr.GetLength(1);
if (width != height)
throw new ArgumentException("Provided array was not square");
List<Point> pointList = new List<Point>();
for (int j = col - distance; j <= col + distance; j++)
using System.Drawing;
namespace BejeweledBot
{
public enum Direction
{
UP,
RIGHT,
DOWN,
LEFT
private void SimplifyColors(Color[,] colors)
{
CurrentColorList = new List<Color>();
int width = colors.GetLength(0);
int height = colors.GetLength(1);
int threshold = 15;
for(int row = 0; row < width; row ++)
for(int col = 0; col < height; col++)
{
Color selectedColor = colors[row, col];
static class ScreenCap
{
public static Bitmap Grab(Rectangle rect)
{
Bitmap bmp = new Bitmap(rect.Width, rect.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(rect.X,
rect.Y,
0, 0,
@msadowski
msadowski / ColorIdentification.cs
Last active July 24, 2016 07:59
ColorIdentification
private void setTilesColors(Bitmap bmp)
{
int offset = TileWidth / 3;
for (int row = 0; row < boardRows; row++)
for(int col = 0; col < boardColumns; col++)
{
int x = corner.X + row * TileWidth + offset;
int y = corner.Y + col * TileWidth + offset;
Rectangle cloneRect = new Rectangle(x, y, TileWidth - 2 * offset, TileWidth - 2 * offset);
PixelFormat format = bmp.PixelFormat;
@msadowski
msadowski / OverlayForm.cs
Created July 24, 2016 07:32
Movable overlay form
using System.Drawing;
using System.Windows.Forms;
namespace BejeweledBot
{
class OverlayForm : Form
{
private int X { get; set; }
private int Y { get; set; }
private bool isDragged = false;
@msadowski
msadowski / LambdaEvents.cs
Created June 23, 2016 06:44
Jon Skeet approach for Event Logging using Lambdas
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
namespace testAdvanced
{
class Program
{
static void Main(string[] args)
import random
import time
caseCounter = 0
randomInt = random.randint(0,100)
randomNormalized = random.random()
caseLessThenHalf = (randomNormalized < 0.5)
caseEven = ((randomInt % 2) == 0)
caseMoreThanTen = (randomInt > 10)