luckfox-pico-sdk/sysdrv/source/mcu/rt-thread/components/benchmark/fhourstones/Main.hs
luckfox-eng29 8f34c2760d project:build.sh: Added fastboot support; custom modifications to U-Boot and kernel implemented using patches.
project:cfg:BoardConfig_IPC: Added fastboot BoardConfig file and firmware post-scripts, distinguishing between
the BoardConfigs for Luckfox Pico Pro and Luckfox Pico Max. project:app: Added fastboot_client and rk_smart_door
for quick boot applications; updated rkipc app to adapt to the latest media library. media:samples: Added more
usage examples. media:rockit: Fixed bugs; removed support for retrieving data frames from VPSS. media:isp:
Updated rkaiq library and related tools to support connection to RKISP_Tuner. sysdrv:Makefile: Added support for
compiling drv_ko on Luckfox Pico Ultra W using Ubuntu; added support for custom root filesystem.
sysdrv:tools:board: Updated Buildroot optional mirror sources, updated some software versions, and stored device
tree files and configuration files that undergo multiple modifications for U-Boot and kernel separately.
sysdrv:source:mcu: Used RISC-V MCU SDK with RT-Thread system, mainly for initializing camera AE during quick
boot. sysdrv:source:uboot: Added support for fastboot; added high baud rate DDR bin for serial firmware upgrades.
sysdrv:source:kernel: Upgraded to version 5.10.160; increased NPU frequency for RV1106G3; added support for
fastboot.

Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
2024-10-14 09:47:04 +08:00

69 lines
2.5 KiB
Haskell

-- This software is copyright (c) 1996-2005 by
-- John Tromp
-- Insulindeweg 908
-- 1095 DX Amsterdam
-- Netherlands
-- E-mail: tromp@cwi.nl
--
-- This notice must not be removed.
-- This software must not be sold for profit.
-- You may redistribute if your distributees have the
-- same rights and restrictions.
module Main where
import Data.Bits
import Data.Char
import Data.Word
import Data.Array.MArray
import Data.Array.IO
import Data.IORef
import Numeric
import CPUTime
import IO
import Connect4(width,height,Game(Game),listGame,isWonGame,isWinnable,goodMoves,size,bsize,moveEval,encode)
import GameTreeSearch(Hash(Hash),GameTree(GTLoss,GTDraw,GTBranch),alphabeta,loss,losswin,win,newTT,TTable,statsTT,intlog,getPosed,ratio,locksize)
ttsize = 8306069 -- should be at least 2^bsize-locksize
makeGameTree game@(Game n _ _ _) h0 h1 =
if n==size-1 then GTDraw else -- assume last move doesn't win
if null children then GTLoss else
if n==size-2 then GTDraw -- two moves left without opponent win is a draw
else GTBranch (Hash lock hash) h0 children where
key = encode game
lock = fromIntegral (key `shiftR` (bsize - locksize))
hash = fromIntegral (key `mod` (fromIntegral ttsize))
children = [(h,makeGameTree g h1 h0) | (h,g) <- goodMoves game]
solve line = do
let moves = map ((\i->i-1).digitToInt) $ filter isDigit line
let game@(Game n _ _ _) = listGame moves
if (isWonGame game) then putStrLn "already lost" else
if isWinnable game then putStrLn "instant win" else do
tt <- newTT ttsize :: IO TTable
hist0 <- thaw moveEval :: IO (IOUArray Int Int)
hist1 <- thaw moveEval :: IO (IOUArray Int Int)
putStrLn$("\nSolving "++).shows n.(("-ply position after "++line)++)$" . . ."
nodes <- newIORef 0 :: IO (IORef Word64)
tstart <- getCPUTime
score <- alphabeta nodes tt losswin (makeGameTree game hist0 hist1)
tend <- getCPUTime
posed <- getPosed tt
n <- readIORef nodes
putStrLn $ ("score = "++).shows score.(" ("++).(("-<=>+"!!(score-loss)):).
(") work = "++) $ show $ intlog posed
let msecs = (tend-tstart) `div` 1000000000
putStrLn $ shows n . (" pos / "++) . shows msecs .
(" msec = "++) . showFFloat (Just 1) (ratio n msecs) $ " Kpos/sec"
stats <- statsTT tt
putStrLn stats
main = do
putStrLn $ ("Fhourstones 3.1 (Haskell)\nBoardsize = "++) .
shows width . ('x':) . shows height . ("\nUsing "++) .
shows ttsize $ " transposition table entries."
input <- getContents
mapM_ solve $ lines input