-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// ################# LICENCE START ################ | ||
// Copyright (c) 2024 ZQBCWG | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
|
||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ################# LICENCE END ################## | ||
{ | ||
name: ["Haskell", ".hs"] | ||
styles: [ | ||
"keyword" > "keyword" | ||
"type" > "type" | ||
"functionName" > "tagName" | ||
"operator" > "operator" | ||
"comment" > "comment" | ||
"string" > "string" | ||
"number" > "number" | ||
] | ||
comment: {startsWith: "--"} | ||
comment: {startsWith: "{-", endsWith: "-}"} | ||
defines: [ | ||
"identifier": /\b[a-zA-Z_][a-zA-Z0-9_']*\b/ | ||
] | ||
contains: [ | ||
{match: /\b(?:[0-9]+|0[xX][0-9a-fA-F]+)\b/, 0: "number"} | ||
{match: /--.*/, 0: "comment"} | ||
{match: /\{-[^}]*-\}/, 0: "comment"} | ||
{match: keywordsToRegex("let in where case of data type newtype deriving instance class do if then else import module as"), 0: "keyword"} | ||
{match: /\b([A-Z][a-zA-Z0-9']*)\b/, 0: "type"} | ||
{match: include("identifier") + /(?=\s*::)/, 0: "functionName"} | ||
{match: /(::|->|<-|=>|=|\+|-|\*|\/|==|\/=|<=|>=|&&|\|\|)/, 0: "operator"} | ||
{match: /".*?"/, 0: "string"} | ||
] | ||
} |
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
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Data.List (elemIndices, sort) | ||
import Data.Set (fromList, toList) | ||
import System.Console.Haskeline (InputT, runInputT, defaultSettings, getInputLine, outputStr, outputStrLn) | ||
-- 一些注释 | ||
rows :: Int | ||
rows = 9 | ||
board :: Board | ||
board = blank | ||
type Board = [[Piece]] | ||
type Position = (Int, Int) | ||
data Piece = B | B' | O | O' | X | X' | AO | AO' | AX | AX' | ||
deriving (Eq, Show) | ||
|
||
data m = PushO | PushX | PushA | Push' | ||
deriving (Eq, Show) | ||
data Tree a = Node a [Tree a] | ||
deriving Show | ||
a :: m -> m | ||
a PushO = PushX | ||
a PushX = PushO | ||
minimax :: ((Int, Position), (Board, Int, Int)) -> Int -> Move -> Bool -> (Label, Label) -> Tree ((Label, Int, Position), (Board, Int, Int)) | ||
minimax ((h, p), (b, hO, hX)) n m f (alpha, beta) | win (b, hO, hX) /= "" || n == 0 || (n == 1 && not (ascending b)) = Node (((hO, hX), h, p), (b, hO, hX)) [] | ||
| otherwise = Node ((bestLabel (map (\(Node ((l, _, _), _) _) -> l) lts) m, h, p), (b, hO, hX)) lts | ||
where lts = alphabeta hpxs n m f (alpha, beta) | ||
hpxs = map (\(h', p', Just b') -> ((h', p'), (if ascending b then settleAscend else id) (initiateAscend b' p', hO, hX))) $ filter (\(_, _, mb) -> mb /= Nothing) $ take breadth [(h', p', move b m p') | (h', p') <- heuristic (b, hO, hX) m f] | ||
|
||
alphabeta :: [((Int, Position), (Board, Int, Int))] -> Int -> Move -> Bool -> (Label, Label) -> [Tree ((Label, Int, Position), (Board, Int, Int))] |