This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using ImageSharp; | |
using ImageSharp.Processing; | |
using SixLabors.Primitives; | |
using OpenTK.Graphics; | |
using OpenTK.Graphics.OpenGL; | |
using static OpenTK.DisplayDevice; | |
using Processing.OpenTk.Core.Extensions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using ImageSharp; | |
using ImageSharp.Processing; | |
using SixLabors.Primitives; | |
using OpenTK.Graphics.OpenGL; | |
using Processing.OpenTk.Core.Extensions; | |
namespace Processing.OpenTk.Core.Textures | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// a switch-case must be in a method | |
public int GetColorRank(String color) | |
{ | |
switch (color) | |
{ | |
case "green": | |
return 1; | |
case "blue": | |
return 2; | |
case "yellow": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
// include prerelease nuget package 'System.Memory' | |
public static class CharSpanExtensions | |
{ | |
public static DateTime ConsumeDateTime(this ReadOnlySpan<char> source, out ReadOnlySpan<char> remaining) | |
{ | |
// date time parsing is a nightmare, so take the heap allocation hit and have DateTime.Parse do it | |
int i = 0; | |
while (i < source.Length) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool HasBit(int mask, int index) | |
{ | |
return (mask & (1 << index)) != 0; | |
} | |
int SetBit(int mask, int index) | |
{ | |
return mask | (1 << index); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OpenGL/Glsl result on left, simulated C# result on the right | |
https://media.discordapp.net/attachments/439873163497832449/517899042055782410/unknown.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fs::File; | |
use std::io::{BufReader, BufRead}; | |
fn score(a : &String) -> i32 { | |
a.chars() | |
.map(|c| (c as i32) - ('a' as i32) + 1) | |
.sum::<i32>() | |
} | |
fn main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk.Web"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net5.0</TargetFramework> | |
<LangVersion>preview</LangVersion> | |
<Nullable>enable</Nullable> | |
</PropertyGroup> | |
<ItemGroup> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// assuming "Board" has a getTokenAt(row, column) function | |
// that returns "red", "blue", or null for each position | |
// and an isInBounds(row, column) function that returns | |
// true if row and column are valid, false if they are off the board | |
// returns number of players tokens that are connected in a direction | |
// (Board, string, int, int, int, int) -> int | |
function countConnectedInDirection(board, player, newTokenRow, newTokenColumn, directionX, directionY) { | |
var count = 1; // number connected, starts at 1 because of the new token | |
// scan "forward" in direction |