{"id":2043,"date":"2025-05-11T16:25:30","date_gmt":"2025-05-11T15:25:30","guid":{"rendered":"https:\/\/blog.univ-angers.fr\/mathsinfo\/?p=2043"},"modified":"2025-05-11T18:18:25","modified_gmt":"2025-05-11T17:18:25","slug":"jeu-color-water-sort-pour-la-hp-prime","status":"publish","type":"post","link":"https:\/\/blog.univ-angers.fr\/mathsinfo\/2025\/05\/11\/jeu-color-water-sort-pour-la-hp-prime\/","title":{"rendered":"Jeu \u00ab\u00a0Color Water Sort\u00a0\u00bb pour HP-Prime"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2025\/05\/image-4.png\"><img loading=\"lazy\" decoding=\"async\" width=\"752\" height=\"620\" src=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2025\/05\/image-4.png\" alt=\"\" class=\"wp-image-2050\" style=\"width:320px;height:auto\" srcset=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2025\/05\/image-4.png 752w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2025\/05\/image-4-300x247.png 300w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2025\/05\/image-4-364x300.png 364w\" sizes=\"auto, (max-width: 752px) 100vw, 752px\" \/><\/a><figcaption class=\"wp-element-caption\">Exemple de d\u00e9but de partie<\/figcaption><\/figure>\n<\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2025\/05\/image-5.png\"><img loading=\"lazy\" decoding=\"async\" width=\"752\" height=\"620\" src=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2025\/05\/image-5.png\" alt=\"\" class=\"wp-image-2052\" style=\"width:318px;height:auto\" srcset=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2025\/05\/image-5.png 752w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2025\/05\/image-5-300x247.png 300w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2025\/05\/image-5-364x300.png 364w\" sizes=\"auto, (max-width: 752px) 100vw, 752px\" \/><\/a><figcaption class=\"wp-element-caption\">Exemple de milieu de partie<\/figcaption><\/figure>\n<\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2025\/05\/image-6.png\"><img loading=\"lazy\" decoding=\"async\" width=\"752\" height=\"620\" src=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2025\/05\/image-6.png\" alt=\"\" class=\"wp-image-2054\" style=\"width:318px;height:auto\" srcset=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2025\/05\/image-6.png 752w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2025\/05\/image-6-300x247.png 300w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2025\/05\/image-6-364x300.png 364w\" sizes=\"auto, (max-width: 752px) 100vw, 752px\" \/><\/a><figcaption class=\"wp-element-caption\">Exemple de fin de partie<\/figcaption><\/figure>\n<\/div>\n\n\n<p>Voici une adaptation tactile du c\u00e9l\u00e8bre jeu de logique <em>WaterSort Puzzle<\/em>, sp\u00e9cialement con\u00e7ue pour la calculatrice HP Prime en langage Python. Le principe est simple, mais diaboliquement addictif : vous devez <strong>verser les couleurs d\u2019un tube \u00e0 l\u2019autre<\/strong> pour que chaque tube contienne <strong>qu\u2019une seule couleur<\/strong>.<\/p>\n\n\n\n<p>Au d\u00e9part, les couleurs sont m\u00e9lang\u00e9es dans plusieurs tubes. \u00c0 chaque tour, vous pouvez d\u00e9placer un empilement de couleur d\u2019un tube vers un autre, <strong>\u00e0 condition que la couleur soit identique<\/strong> ou que le tube soit vide. L\u2019objectif est de <strong>reconstituer les couleurs uniform\u00e9ment<\/strong> dans chaque tube, sans d\u00e9border.<\/p>\n\n\n\n<p>\ud83d\udca1 Ce jeu fait appel \u00e0 la logique, \u00e0 l\u2019anticipation\u2026 et un peu \u00e0 votre patience !<\/p>\n\n\n\n<p><strong>Fonctionnalit\u00e9s :<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Interface graphique simple et intuitive adapt\u00e9e \u00e0 l\u2019\u00e9cran de la HP Prime<\/li>\n\n\n\n<li>Affichage color\u00e9 dynamique (jusqu\u2019\u00e0 8 couleurs diff\u00e9rentes)<\/li>\n\n\n\n<li>Bouton <kbd>\u00ae<\/kbd> pour <strong>recommencer<\/strong> le niveau si vous \u00eates bloqu\u00e9<\/li>\n\n\n\n<li>D\u00e9tection automatique de victoire<\/li>\n<\/ul>\n\n\n\n<p>Vous trouverez ci-dessous le <strong>code source complet<\/strong> ainsi que le <a href=\"https:\/\/univangersfr-my.sharepoint.com\/:u:\/g\/personal\/eric_schrafstetter_univ-angers_fr1\/EXtzzVPF_W1HmYS1DcI_0UkBFajhkebaJY2zVGiyOiaoqA?e=WygFcZ\">fichier <strong>watercolor.hpprgm<\/strong><\/a> (fonctionne avec la version 2.1 du 13\/04\/2023 et les suivantes) :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#python jeu\nfrom hpprime import *\nfrom urandom import choice\n\ncouleurs_rgb = {\n    \"a\": 0x845ec2,\n    \"b\": 0xd65db1,\n    \"c\": 0xff6f91,\n    \"d\": 0xff9671,\n    \"e\": 0xffc75f,\n    \"f\": 0xf9f871,\n    \"g\": 0x9bde7e,\n    \"h\": 0x4bbc8e\n}\nliste_couleurs = list(couleurs_rgb.keys())\n\nLARGEUR_TUBE = 20\nHAUTEUR_TUBE = 60\nESPACEMENT_X = 80\nESPACEMENT_Y = 74\nMARGE_X = 45\nMARGE_Y = 20\nCOLONNES = 3\nLIGNES = 3\nTOTAL_COULEURS = 7\nNOIR = 0x000000\nBLANC = 0xFFFFFF\nBG = 0x03132C\n\ndef position_tube(index):\n    col = index % COLONNES\n    lig = index \/\/ COLONNES\n    x = MARGE_X + col * ESPACEMENT_X\n    y = MARGE_Y + lig * ESPACEMENT_Y\n    return x, y\n\ndef attendre_clic():\n    while True:\n        f1, _ = eval('mouse')\n        if f1:\n            while eval('mouse')&#091;0]: pass\n            return f1&#091;:2]\n\ndef tube_clique(x, y):\n    for i in range(9):\n        tx, ty = position_tube(i)\n        if tx - ESPACEMENT_X \/ 2 &lt; x &lt; tx + LARGEUR_TUBE + ESPACEMENT_X \/ 2 and ty &lt;= y &lt;= ty + HAUTEUR_TUBE:\n            return i\n    return None\n\ndef dessiner_tubes(tubes, selectionne=None):\n    fillrect(0, 0, 0, 320, 240, BG, BG)\n    for i, tube in enumerate(tubes):\n        x, y = position_tube(i)\n        bordure = 0x00FF00 if i == selectionne else BLANC\n        rect(0, x-2, y-2, LARGEUR_TUBE+4, HAUTEUR_TUBE+4, bordure)\n        rect(0, x-3, y-3, LARGEUR_TUBE+6, HAUTEUR_TUBE+6, bordure)\n        fillrect(0, x, y-3, LARGEUR_TUBE, 3, BG, BG)\n        h = HAUTEUR_TUBE \/\/ 4\n        for j, couleur in enumerate(tube):\n            c = couleurs_rgb.get(couleur)\n            fillrect(0, x, y + HAUTEUR_TUBE - (j + 1)*h, LARGEUR_TUBE, h, c, c)\n    # Bouton recommencer\n    textout(0, 270, 110, chr(174), BLANC)\n\ndef sommet_identique(tube):\n    if not tube: return None, 0\n    sommet = tube&#091;-1]\n    compteur = 1\n    for i in range(len(tube)-2, -1, -1):\n        if tube&#091;i] == sommet: compteur += 1\n        else: break\n    return sommet, compteur\n\ndef peut_verser(depuis, vers):\n    if not depuis or len(vers) &gt;= 4:\n        return False\n    couleur, nb = sommet_identique(depuis)\n    if not vers: return True\n    return vers&#091;-1] == couleur\n\ndef verser(depuis, vers):\n    if not peut_verser(depuis, vers): return\n    couleur, nb = sommet_identique(depuis)\n    espace = 4 - len(vers)\n    a_verser = min(nb, espace)\n    for _ in range(a_verser):\n        vers.append(depuis.pop())\n\ndef generer_tubes():\n    couleurs = &#091;]\n    for couleur in liste_couleurs&#091;:TOTAL_COULEURS]:\n        couleurs += &#091;couleur]*4\n    melange = &#091;]\n    while couleurs:\n        c = choice(couleurs)\n        couleurs.remove(c)\n        melange.append(c)\n    tubes = &#091;melange&#091;i*4:(i+1)*4] for i in range(TOTAL_COULEURS)]\n    tubes += &#091;&#091;] for _ in range(9 - TOTAL_COULEURS)]\n    return tubes\n\ndef a_gagne(tubes):\n    for tube in tubes:\n        if not tube: continue\n        if len(tube) != 4: return False\n        if any(c != tube&#091;0] for c in tube): return False\n    return True\n\ndef afficher_message_gagne():\n    fillrect(0, 50, 90, 220, 60, BLANC, couleurs_rgb&#091;\"d\"])\n    textout(0, 85, 105, \"Bravo ! Vous avez gagn\u00e9\", NOIR)\n    fillrect(0, 110, 130, 100, 25, BLANC, couleurs_rgb&#091;\"g\"])\n    textout(0, 130, 135, \"REJOUER\", NOIR)\n\ndef attendre_redemarrage():\n    while True:\n        x, y = attendre_clic()\n        if 110 &lt;= x &lt;= 210 and 130 &lt;= y &lt;= 155: return\n\ndef bouton_redemarrer(x, y):\n    return 260 &lt;= x &lt;= 300 and 80 &lt;= y &lt;= 130\n\ndef main():\n    while True:\n        tubes = generer_tubes()\n        tubes_depart = &#091;tube&#091;:] for tube in tubes]\n        selection = None\n        while True:\n            dessiner_tubes(tubes, selection)\n            if a_gagne(tubes):\n                afficher_message_gagne()\n                attendre_redemarrage()\n                break\n            x, y = attendre_clic()\n            if bouton_redemarrer(x, y):\n                tubes = &#091;tube&#091;:] for tube in tubes_depart]\n                selection = None\n                continue\n            index = tube_clique(x, y)\n            if index is None:\n                selection = None\n                continue\n            if selection is None:\n                if tubes&#091;index]: selection = index\n            elif selection == index:\n                selection = None\n            else:\n                verser(tubes&#091;selection], tubes&#091;index])\n                selection = None\n\nmain()\n#end\n\nEXPORT watercolor()\nBEGIN\n  wait(.3);\n  python(jeu);\nEND;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Voici une adaptation tactile du c\u00e9l\u00e8bre jeu de logique WaterSort Puzzle, sp\u00e9cialement con\u00e7ue pour la calculatrice HP Prime en langage Python. Le principe est simple, mais diaboliquement addictif : vous devez verser les couleurs d\u2019un tube \u00e0 l\u2019autre pour que &hellip; <a href=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/2025\/05\/11\/jeu-color-water-sort-pour-la-hp-prime\/\">Continuer la lecture <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":4913,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2043","post","type-post","status-publish","format-standard","hentry","category-non-classe"],"_links":{"self":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts\/2043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/users\/4913"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/comments?post=2043"}],"version-history":[{"count":5,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts\/2043\/revisions"}],"predecessor-version":[{"id":2056,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts\/2043\/revisions\/2056"}],"wp:attachment":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/media?parent=2043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/categories?post=2043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/tags?post=2043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}