From c9eb1b5bc962fd784b63d5059f543c352e089a0b Mon Sep 17 00:00:00 2001 From: flavis Date: Sun, 15 Sep 2019 23:27:39 +0200 Subject: [PATCH] add debug info to ai --- src/Skat/AI/Rulebased.hs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Skat/AI/Rulebased.hs b/src/Skat/AI/Rulebased.hs index bb82aef..64bb3a9 100644 --- a/src/Skat/AI/Rulebased.hs +++ b/src/Skat/AI/Rulebased.hs @@ -250,7 +250,7 @@ chooseStatistic = do 3 -> 3 -- simulate only partially 4 -> 3 - 5 -> 2 + 5 -> 3 6 -> 2 7 -> 1 8 -> 1 @@ -277,6 +277,7 @@ chooseStatistic = do limit = if depth == 1 && length table == 2 then 1 else min 10000 $ realDisNo `div` 2 + liftIO $ putStrLn $ "players hand" ++ show handCards liftIO $ putStrLn $ "possible distrs without simp " ++ show realDisNo liftIO $ putStrLn $ "possible distrs " ++ show reducedDisNo vals <- M.toList <$> foldWithLimit limit runOnPiles M.empty piless @@ -307,6 +308,7 @@ chooseOpen = do piles <- showPiles hand <- gets getHand let myCards = handCards hand piles + liftIO $ putStrLn $ show hand ++ " chooses from " ++ show myCards possible <- filterM (P.isAllowed myCards) myCards case length myCards of 0 -> do @@ -329,6 +331,7 @@ chooseSimulating = do results <- mapM simulate cs let both = zip results cs best = maximumBy (comparing fst) both + liftIO $ putStrLn $ "results " ++ show both return $ snd best simulate :: (MonadState AIEnv m, MonadPlayerOpen m) @@ -341,6 +344,7 @@ simulate card = do myTeam <- gets getTeam myHand <- gets getHand depth <- gets simulationDepth + liftIO $ putStrLn $ "simulate: " ++ show myHand ++ " plays " ++ show card let newDepth = depth - 1 -- create a virtual env with 3 ai players ps = Players @@ -364,7 +368,8 @@ predictValue (own, others) = do piles <- showPiles let cs = handCards hand piles pot <- potential cs - return $ own + pot + --return $ own + pot + return (own-others) potential :: (MonadState AIEnv m, MonadPlayerOpen m) => [Card] -> m Int @@ -383,7 +388,7 @@ position card = do let effCol = effectiveColour tr card l = M.toList guess cs = filterMap ((==effCol) . effectiveColour tr . fst) fst l - csInd = zip [0..] cs + csInd = zip [0..] (reverse cs) Just (pos, _) = find ((== card) . snd) csInd return pos @@ -401,8 +406,11 @@ chooseLead :: (MonadState AIEnv m, MonadPlayer m) => m Card chooseLead = do cards <- gets myHand possible <- filterM (P.isAllowed cards) cards + liftIO $ putStrLn $ "choosing lead from " ++ show possible pots <- mapM leadPotential possible - return $ snd $ maximumBy (comparing fst) (zip pots possible) + let ps = zip pots possible + liftIO $ putStrLn $ "lead potential of cards " ++ show ps + return $ snd $ maximumBy (comparing fst) ps mkAIEnv :: Team -> Hand -> Int -> AIEnv mkAIEnv tm h depth = AIEnv tm h [] [] [] newGuess depth