Skip to content

Instantly share code, notes, and snippets.

#define BishopAttacks(sq,occ)
(MagicAttacks[
BOffset[(sq)] +
(((BMagicMask[(sq)] & (occ)) * BMagic[(sq)]) >> BShift[(sq)])
])
#define RookAttacks(sq,occ)
(MagicAttacks[
ROffset[(sq)] +
#define BishopAttacks(sq,occ)
(MagicAttacks[
BOffset[(sq)] +
(((BMagicMask[(sq)] & (occ)) * BMagic[(sq)]) >> BShift[(sq)])
])
#define RookAttacks(sq,occ)
(MagicAttacks[
ROffset[(sq)] +
(((RMagicMask[(sq)] & (occ)) * RMagic[(sq)]) >> RShift[(sq)])
@nagat01
nagat01 / gist:759506
Created December 30, 2010 05:40
Computer Chess Program which used Haskell Data.Array
module Bd where
import Array
import Char
import Utils
-- types
data Pc=Pc {co::Co, pcType::PcType} deriving Eq
data PcType = Ro | Ni | Bi |
Ki | Qu | Pa deriving (Eq,Enum)
data Co = Bl | Wh deriving (Eq,Enum)
// I'm trying to translate C# code to F# for my training
// http://www.fincher.org/tips/Languages/csharp.shtml
open System
open System.IO
// A. Hello world program
let helloWorld = Console.WriteLine "Hello World!"
// C. Read and print an entire file
@nagat01
nagat01 / gist:1004102
Created June 2, 2011 08:12
F# static variable,static constructor,destructor
// TODO: Test2's destructor does not work
open System
open System.IO
open System.Net
type Test2() =
// static variable
[<DefaultValue>]
static val mutable private i:int
// static constructor
@nagat01
nagat01 / C# to F# 2.fs
Created June 2, 2011 09:50
My training.Translating C# code to F#.
(*
My training.Translating C# code to F#.
http://www.fincher.org/tips/Languages/csharp.shtml
*)
open System
open System.IO
open System.Net
@nagat01
nagat01 / gist:1008514
Created June 5, 2011 00:05
F# : Regex.IsMatch example
open System
open System.Text.RegularExpressions
// http://msdn.microsoft.com/en-us/library/ms228595(v=vs.80).aspx#Y300
let regexIsMatchSample lines pattern =
// for line in
List.iteri(fun i line ->
if Regex.IsMatch(line,pattern,RegexOptions.IgnoreCase) then
printfn"%3d : %s" i line) lines
regexIsMatchSample
@nagat01
nagat01 / gist:1008584
Created June 5, 2011 02:21
$ with RegexOptions.Multiline does not work for verbatim string's end of lines
// $ with RegexOptions.Multiline does not work for verbatim string's end of lines
open System
open System.Text.RegularExpressions
let matchEndOfLineWord =
let regex = new Regex("\w+$",RegexOptions.Multiline)
regex.Matches("Yuki Nagato\nHaruhi Suzumiy\nMikuru Asahina")
|>printfn"%A"
regex.Matches(@"Kyon
@nagat01
nagat01 / gist:1008649
Created June 5, 2011 04:32
F# : Regex.Match, Regex.Matches
(*
http://msdn.microsoft.com/en-us/library/30wbz966(v=vs.71).aspx#Y470
Match : finds first occurrence
Match.Success : is match succeed?
Match.Groups : collection of captured groups
Matches : store every non-overlapping occurrences to Item
Matches.Item : indexed property of mathed string
*)
open System
@nagat01
nagat01 / xboxdownload.fs
Created June 6, 2011 10:09
C#たん講座 第1.5回の5 F#版
// http://codezine.jp/article/detail/5696?p=5
// I don't own any right for this program.
// Read above url for read original program.
// You can escape double quote by writing it
// twice in verbatim string literal.
// [^""]* : match to double quote any times
// \> : unknown
// \< :
// (?<title>.*) : match to any character any times
// and this group is named as "title"