Example #1
0
def seed_and_solve(f, seed):

    if seed:
        s = solitaire.Solitaire(seed=seed)
    else:
        s = solitaire.Solitaire()
    return f(s)
Example #2
0
    if args.parallel > 1:
        jobs = []
        with Pool(args.parallel) as p:
            for i in range(0, count):
                if seed:
                    tseed = seed + str(i)
                jobs.append(p.apply_async(seed_and_solve, (solve_game, tseed)))
            p.close()
            p.join()
            for job in jobs:
                res.append(job.get(timeout=1))
    else:
        for i in range(0, count):

            if seed:
                s = solitaire.Solitaire(seed=seed + str(i))
            else:
                s = solitaire.Solitaire()

            res.append(solve_game(s))

    end = timer()

    totaldur = end - start
    avgdur = totaldur / float(count)

    solvecount = 0
    colltotal = 0
    collbest = 0
    turntotal = 0
    turnbest = 99999
Example #3
0
 def start_game(self, game):
   self.moves = 0
   self.game = s.Solitaire() if game is None else game
Example #4
0
 def setUp(self):
     self.solitaire1 = solitaire.Solitaire()
     self.solitaire2 = solitaire.Solitaire()
Example #5
0
    if card is None and -1 in moves:
      card = self.game.reserve.pop()
    return self.game.card_to_foundation(card)
  
  def get_longest_visible_column(self, moves):
    dst = None
    maxi = 0
    for col in moves:
      if self.visible_cards_count[col] > maxi:
        maxi = self.visible_cards_count[col]
        dst = col
    return dst

def count_visible(src: deck.Deck):
  v_count = 0
  if src.is_empty():
    return v_count
  for c in src:
    if c.visible == True:
      v_count += 1
  return v_count


if __name__ == '__main__':
  p = Player(s.Solitaire(shuffle=False))
  print(p.game.display_game())
  go = None
  while(go != True):
    go = p.best_move()
    print(p.game.display_game())
    print(p.moves)
Example #6
0
        card = selected_cards[0]
        if card.highlight:
            pygame.draw.rect(screen, BLUE,
                             pygame.Rect(card.x, card.y, 64 * 2, 89 * 2), 5)


while True:
    # --- Event logic should go here
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE:
                ai.predict(game)
            if event.key == pygame.K_RETURN:
                game = solitaire.Solitaire()
                game.setup()

        if event.type == pygame.MOUSEBUTTONDOWN:
            pass

        if event.type == pygame.MOUSEBUTTONUP:
            pos = pygame.mouse.get_pos()
            click_outside = True

            #stock
            if mouse_on_card(pos, [25, 25]):
                game.draw_stock_cards()
            #waste pile
            if mouse_on_card(pos, [250, 25]):
                card = game.get_top_wastepile()
Example #7
0
# Defining the phrase which will be used by the Solitaire encryption
print('Select a phrase for encryption:')
phrase = input()

# Sending and reading phrase with which we will use the Solitaire encryptions
formatedPhrase = functions.intListToString(knap.encrypt(phrase, pubKey))
functions.send_msg(conn, formatedPhrase)

# Assembling the secret phrase
phrase = knap.decrypt(functions.stringToIntList(functions.read_from_socket(conn))).decode('utf-8') + phrase
print('Assembled the encrypting phrase with my peer')
print(phrase)

# Creating the Solitaire encryption tool
sol = solitaire.Solitaire()
sol.phraseShuffle(phrase)

print('Waiting for conversation to start')

msg = ''
while msg != 'exit':
    formatedMsg = functions.stringToIntList(functions.read_from_socket(conn).decode('utf-8'))
    if formatedMsg == 'exit':
        break
    print(sol.decrypt(formatedMsg))
    msg = input()
    encMsg = functions.intListToString(sol.encrypt(msg))
    functions.send_msg(conn, encMsg)

functions.send_msg(socket, json.dumps({"close": True}))
Example #8
0
import solitaire as sol
import datetime
import smtplib
import variables as vars

soli = sol.Solitaire()  # Solitaire object
result = 0  # For results

sender = vars.email
receivers = [vars.email]
print "Run started at " + datetime.datetime.now().time().isoformat()

for i in xrange(1000000000):
    result = soli.solve()
    if result < 5:
        print "Run #" + repr(i) + ": " + repr(result) + " cards left."

        if result == 0:  # Solved

            message = "From: Kristoffer <" + vars.email + """>
To: Kristoffer Lorentsen <""" + vars.email + """>
Subject: Solitaire solved!

The Solitaire was solved on run #""" + repr(
                i) + " at " + datetime.datetime.now().time().isoformat()

            try:
                smtpObj = smtplib.SMTP('smtp.gmail.com', 587)
                smtpObj.ehlo()
                smtpObj.starttls()
                smtpObj.ehlo()
Example #9
0
def new_game():
    game = solitaire.Solitaire()
    game.setup()
    return game