Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6732909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:42:22+00:00 2026-05-26T10:42:22+00:00

So I wrote a hexapawn game and I’m trying to make a function that

  • 0

So I wrote a hexapawn game and I’m trying to make a function that returns True if the board is in a winning state, it looks like this at the moment:

checkWin :: BoardState -> Bool
checkWin b1@(blackPieces,whitePieces,turn,size,win)
  |(length blackPieces) == 0 = True
  |(length whitePieces) == 0 = True
  |length (generateMoves b1) == 0 = True
  |otherwise = False

So this works if there are no black or white pieces left or if no one can make a move but it doesn’t work if an opposing pawn reaches the end of the board(another way to win in hexapawn). The variables blackPieces and whitePieces are list of coordinates ie [(1,1),(2,1),(3,1)] of where those pawns are on the board of size n (turn is true if its whites turn)

I was tempted to add these conditions to the method but the compiler didn’t like it.

  |(_,1) `elem` whitePieces = True
  |(_,size) `elem` blackPieces = True

Is there any other way to say “Are there any tuples in whitePieces who’s second element is a 1(i.e reached the other side of the board).”

Thanks in advance for your helpful comments.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:42:23+00:00Added an answer on May 26, 2026 at 10:42 am

    So we want a function that receives a list of something [a], a predicate over somethings (a->Bool) and returns a Bool. A quick check on Hoogle and we get back

    any :: (a -> Bool) -> [a] -> Bool
    Applied to a predicate and a list, any determines if any element of
    the list satisfies the predicate. For the result to be False, the list must be finite
    

    So

     (_,1) `elem` whitePieces 
    

    becomes

     any (\(_, x) -> x == 1) whitePieces
    

    or (as eternalmatt reminds me)

    any (==1) ( map snd whitePieces )
    

    and so on


    By the way, the best way to check is a list is empty is via pattern matching or the null function. The length == 0 method will walk through all of the linked list and might even enter an infinite loop if the list is infinite.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a query that returns monthly sales. SELECT count(O.orderid) as Number_of_Orders, concat (MonthName(FROM_UNIXTIME(O.`date`)),'
I wrote a windows service using VB that read some legacy data from Visual
I wrote myself a little downloading application so that I could easily grab a
I wrote a component that displays a filename, a thumbnail and has a button
I wrote a simple tool to generate a DBUnit XML dataset using queries that
I wrote an application that currently runs against a local instance of MySql. I
I wrote a setter and getter method following Apple's conventions and noticed that despite
I wrote a piped shell command that has multiple pipes in it that works
I wrote a program that uses OLE and it was working fine until I
Wrote a small app that accesses a bunch of search websites and puts the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.