Skip to content

Commit

Permalink
added project
Browse files Browse the repository at this point in the history
  • Loading branch information
tiemonl committed Jun 26, 2018
1 parent 6aff0ad commit 0fd064a
Show file tree
Hide file tree
Showing 78 changed files with 5,224 additions and 0 deletions.
Binary file added .vs/fisher/v15/.suo
Binary file not shown.
Empty file.
Binary file added .vs/fisher/v15/Server/sqlite3/storage.ide
Binary file not shown.
Empty file added .vs/fisher/v15/sqlite3/db.lock
Empty file.
Binary file added .vs/fisher/v15/sqlite3/storage.ide
Binary file not shown.
25 changes: 25 additions & 0 deletions fisher.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2002
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fisher", "fisher\fisher.csproj", "{93668F5E-8746-4070-AE80-19D2609EDE78}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{93668F5E-8746-4070-AE80-19D2609EDE78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93668F5E-8746-4070-AE80-19D2609EDE78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93668F5E-8746-4070-AE80-19D2609EDE78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93668F5E-8746-4070-AE80-19D2609EDE78}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {10017706-D0A3-4594-BD5E-4DFBFA8ED2D2}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions fisher/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
90 changes: 90 additions & 0 deletions fisher/FindWeight.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;

namespace fisher {
class FindWeight {
//static void Main(string[] args) {
// Bitmap need = new Bitmap("C:\\Users\\Liam\\Dropbox\\Coding Shit\\Bit Heroes Fishing\\Weight\\zero.bmp");
// Bitmap hay = new Bitmap("C:\\Users\\Liam\\Dropbox\\Coding Shit\\Bit Heroes Fishing\\fisher\\fisher\\bin\\Debug\\screenie.bmp");
// Point? pt = Find(hay, need);
// Console.WriteLine(pt.ToString());
// Console.ReadLine();
//}
public static Point? Find(Bitmap haystack, Bitmap needle) {
if (null == haystack || null == needle) {
return null;
}
if (haystack.Width < needle.Width || haystack.Height < needle.Height) {
return null;
}

var haystackArray = GetPixelArray(haystack);
var needleArray = GetPixelArray(needle);

foreach (var firstLineMatchPoint in FindMatch(haystackArray.Take(haystack.Height - needle.Height), needleArray[0])) {
if (IsNeedlePresentAtLocation(haystackArray, needleArray, firstLineMatchPoint, 1)) {
return firstLineMatchPoint;
}
}

return null;
}

private static int[][] GetPixelArray(Bitmap bitmap) {
var result = new int[bitmap.Height][];
var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb);

for (int y = 0; y < bitmap.Height; ++y) {
result[y] = new int[bitmap.Width];
Marshal.Copy(bitmapData.Scan0 + y * bitmapData.Stride, result[y], 0, result[y].Length);
}

bitmap.UnlockBits(bitmapData);

return result;
}
private static IEnumerable<Point> FindMatch(IEnumerable<int[]> haystackLines, int[] needleLine) {
var y = 0;
foreach (var haystackLine in haystackLines) {
for (int x = 0, n = haystackLine.Length - needleLine.Length; x < n; ++x) {
if (ContainSameElements(haystackLine, x, needleLine, 0, needleLine.Length)) {
yield return new System.Drawing.Point(x, y);
}
}
y += 1;
}
}

private static bool ContainSameElements(int[] first, int firstStart, int[] second, int secondStart, int length) {
for (int i = 0; i < length; ++i) {
if (i == 19) {
System.Diagnostics.Debugger.Break();
}
if (second[i + secondStart].Equals(-1)) {
continue;
}
if (first[i + firstStart] != second[i + secondStart]) {

return false;
}
}
return true;
}

private static bool IsNeedlePresentAtLocation(int[][] haystack, int[][] needle, Point point, int alreadyVerified) {
//we already know that "alreadyVerified" lines already match, so skip them
for (int y = alreadyVerified; y < needle.Length; ++y) {
if (!ContainSameElements(haystack[y + point.Y], point.X, needle[y], 0, needle[0].Length)) {
return false;
}
}
return true;

}
}
}
Loading

0 comments on commit 0fd064a

Please sign in to comment.